Compare dates in different format

Utpal Dutta1
Mega Guru

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

12 REPLIES 12

Chandu Telu
Tera Guru
Tera Guru

Hi 

Check the below link it may help you

https://community.servicenow.com/community?id=community_question&sys_id=80cd59041b66f810ada243f6fe4bcb4a

https://community.servicenow.com/community?id=community_question&sys_id=0aa7ff65db816744b2102926ca9619c0

 

Thanks

Chandu Telu

 

Please Mark the answer helpful/correct , if it is

Thanks but it's not helpful

Aman Kumar S
Kilo Patron

Hey,

I think when we talk about the date formatting, its all for the display value, the backend value remains consistent 

Follow below article to validate:

https://community.servicenow.com/community?id=community_question&sys_id=890cc725db9cdbc01dcaf3231f961964

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

@Utpal Dutta 

Hi,

no worries in date format

You can use UI policy for this with no script

Like this

find_real_file.png

find_real_file.png

Output with Date Format yyyy-MM-dd See the date format for Opened

find_real_file.png

Output with date format - dd/MM/yyyy - See the date format for Opened

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader