Why does gs.now() return dates in the user defined format?

ninnesr
Kilo Contributor

Consider the following: Our system default date format is dd-mm-yyyy (Australian format)


var today = gs.now(); // returns format dd-mm-yyyy
var expires = current.u_expiry; // displays dd-mm-yyyy on the form, returns yyyy-mm-dd format, as stored in the database

//if I do the following
var exp_days = gs.dateDiff(today, expires); // Returns tens of thousands of days in the past

//so have to do the following . . .
var expires = expires.split('-').reverse().toString().replace(/,/g,'-'); //manipulate the date from yyyy-mm-dd to dd-mm-yyyy

var exp_days = gs.dateDiff(today, expires); // calculate days between the expiry and today. Returns +-dd hh:mm:ss + if in the future - if in the past



If I used gs.beginningOfToday() instead of gs.now() then both would be in the yyyy-mm-dd format. However I would still have to change them to dd-mm-yyyy to use gs.dateDiff() as it uses the user defined date format for it's input dates.

That's just annoying!!!

It just seems strange to me that the majority of the time one would use gs.now() or gs.nowDateTime() would be to calculate something in code, where all other dates are presented in the standard of yyyy-mm-dd. It's not an issue if your defined date format is yyyy-mm-dd but it's a hassle for us Aussies.

Is there a function that converts user defined date formats into system time formats, or visa-versa?
1 REPLY 1

tyler_jones
ServiceNow Employee
ServiceNow Employee

Another approach is just to make both in the User's time zone:



var expires = current.u_expiry.getDisplayValue();