Need help to understand date/time functions

amaradiswamy
Kilo Sage

Hi All,

I got a doubt while working with date/time field manipulations. for example, if i need to trigger a notification in the workflow if the current date is less than a date/time field selected in the catalog time. From the wiki article, i got how to check for this condition. But, how can i acheive this without conflicting the time zones. (for example if i use gs.nowDateTime() it is giving date/time in user's time zone, if i use gs.nowNoTZ() it is giving date/time in GMT, so if a user from us time zone has raised a request then i think it may conflicted. so i was totally confused with these, could you please some one help me to understand this clearly(with example if possible).

Thanks and regards,

Swamy

4 REPLIES 4

akashsrm100
Kilo Guru

The best practice to use Date time function is to write server side code(script include).


For more info GlideSystem Date and Time Functions - ServiceNow Wiki




Thanks


Akash Sharma


jagarnathn
Tera Expert

You just make the custom date to display in the users time zone. So that it will be easy to compare.



var dt= new GlideDateTime();


dt.setvalue(current.due_date);



var actual_date=dt.getDisplayValue();



if(actual date < gs.nowDateTime()){



write your script here ;



}


Hi Behera,



Thanks for your reply. I am aware of these functions. My doubt is like when we should use gs.nowDateTime() and gs.nowNoTZ()?( how we can eliminate the time zone problem)?



Thanks and regards,


Swamy


Mohammed Lais1
Mega Guru

HI Amaradi,


try using this script.  


var actual_date_user_timezone = formatDate(actual_date, g_user_date_time_format);


this code will change the actual time to your user time zone.