Compare dates in different format

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 10:10 PM
Hi all,
We are looking for a way to compare different date formats. We store date in a string field & then we want to add a validation on server side that if the date is before 02/02/2022 then abort insertion.
But the problem is that user who submits the record in this table, he might have different date format which will cause issues in this date comparison since we have used (dd/MM/yyyy) & user may have date format as (yyyy/MM/dd). Also before hand we don't know user will have which format in his profile.
So what I'm looking for is either a way to compare 2 different date formats or maybe convert any string date format to a common format which helps in date comparison.
Thanks,
Utpal
- Labels:
-
Search
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 11:30 PM
Hi Ankur,
Thank you for your reply but I want to do a server side validation. I would appreciate if you could help me with that.
Thanks,
Utpal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 11:38 PM
Try below code:
var gdt = new GlideDate();
var gdt1 = new GlideDate();
gdt1.setValue("02-02-2022");
gs.info(gdt);
if(gdt > gdt1)
gs.info("future");
else
gs.info("past");
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2022 12:05 AM
I'm afraid it won't work when date formats are different
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 11:42 PM
Any reason you wish to do server side when it can be easily done without script using UI policy?
Is this a business requirement to use server side instead of client side?
I would recommend using low-code wherever it can be done so that it can be easily maintained.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2022 12:01 AM
Yes Ankur, This is a business requirement. We have already implemented it using UI policy but seems like our Info Sec team is having concern with Client side validation & they want us to validate this in server.