How to get just the date and not the time using something similar to javascript:gs.nowDateTime()

mzmoore
Mega Expert

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.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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:

find_real_file.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Saiganeshraja
Kilo Sage
Kilo Sage
javascript:gs.now()

 

Mark correct and helpful

How do I change the date format to day month year

var date= new GlideDate();
var date2 = date.getByFormat('yyyy/MM/dd'); // Format according to your requirement
//gs.print(date2);

Ankur Bawiskar
Tera Patron
Tera Patron

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:

find_real_file.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader