- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 10:55 PM
I'm trying to set a default value in a variable field to return current date without the time. How do I alter javascript:gs.nowDateTime() to only get the date?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 11:17 PM
Hi,
remember you should not use gs.now()
Please use GlideDateTime which works in both Global + Scoped application
var gdt = new GlideDateTime();
var todayDate = gdt.getDate();
gs.info(todayDate);
To convert to your format use this
var gdt = new GlideDateTime();
var todayDate = gdt.getDate();
var dt = new GlideDate();
dt.setValue(todayDate);
var myFormat = 'dd-MM-yyyy';
var myFormatValue = dt.getByFormat(myFormat);
gs.info(myFormatValue);
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 10:59 PM
javascript:gs.now()
Mark correct and helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 11:05 PM
How do I change the date format to day month year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 11:21 PM
var date= new GlideDate();
var date2 = date.getByFormat('yyyy/MM/dd'); // Format according to your requirement
//gs.print(date2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 11:17 PM
Hi,
remember you should not use gs.now()
Please use GlideDateTime which works in both Global + Scoped application
var gdt = new GlideDateTime();
var todayDate = gdt.getDate();
gs.info(todayDate);
To convert to your format use this
var gdt = new GlideDateTime();
var todayDate = gdt.getDate();
var dt = new GlideDate();
dt.setValue(todayDate);
var myFormat = 'dd-MM-yyyy';
var myFormatValue = dt.getByFormat(myFormat);
gs.info(myFormatValue);
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader