- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2014 07:01 PM
In Client Script, how can I compare 2 dates(with time) that are in different format.
ex yyyy-mm-dd HH:mm:ss and MM-dd-yyyy hh:mm:ss (12 hours)
Somehow I need to convert the 2nd date&time to system format and then compare to the first date. But I do not know how. Please assist.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2014 06:55 AM
Using "getDisplayValue()" will retrieve the date/time in the person's timezone and display format. So you could use that on both date variables to force them into the same timezone.
gdate.getDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2014 01:08 PM
That is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2014 03:39 PM
Did you ever find a solution to this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2014 04:39 AM
No, not yet. I put it on the side for now as I am working on another thing.
Thanks for following up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2014 05:13 AM
Hi Jocelyn,
Try this code:
var dateFormat=g_user_date_time_format;
var D_one = g_form.getValue("<first date>");
var D_two = g_form.getValue("<second date>");
var dateOneFormat = getDateFromFormat(D_one , g_user_date_time_format);
var dateTwoFormat = getDateFromFormat(D_two , g_user_date_time_format);
var difference=(dateOneFormat - dateTwoFormat );
Hope this solve your issue.
Here are two reference pages also which will be of help to anyone having similar issues.
https://community.servicenow.com/message/703546#703546
http://wiki.servicenow.com/index.php?title=Validate_Date_and_Time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2014 06:46 AM
Thanks a bunch Anurag. My other challenge is the timezone.
When I try to compare the dates coming from the server and the new entered date, even though they are the same, the system returns "false" bec of the timezone difference.
Do you have any fix for this?