Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get date in script

codedude
Mega Expert

I am trying to grab the current date dynamically. What is the best way for me to grab the date in this format?

Saturday, November 7, 2015

I will be doing this in a UI page if that helps any.....

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

var inputDate = new GlideDateTime();


var initialDateTimeFormat = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  


var initialFormattedDate = initialDateTimeFormat.parse(inputDate);


var finalDatetimeFormat = new Packages.java.text.SimpleDateFormat("EEEE,MMMM dd,yyyy");  


gs.print(finalDatetimeFormat.format(initialFormattedDate));


View solution in original post

7 REPLIES 7

tombialkowski
Giga Expert

I am still very new to Service Now, and do not know the full capabilities of using JavaScript within it. However, with that in mind, I hope this helps get you started:



http://stackoverflow.com/questions/1531093/how-to-get-current-date-in-javascript


Kalaiarasan Pus
Giga Sage

var inputDate = new GlideDateTime();


var initialDateTimeFormat = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  


var initialFormattedDate = initialDateTimeFormat.parse(inputDate);


var finalDatetimeFormat = new Packages.java.text.SimpleDateFormat("EEEE,MMMM dd,yyyy");  


gs.print(finalDatetimeFormat.format(initialFormattedDate));


Is there anyway to get this into eastern time? It is putting it 5 hours ahead for me....


Haven't tested it but this function would use your timezone


Just check the link to find method that suits your requirement. There are few other  methods using gs object. Have a look at that as well.