Help with Date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 03:53 AM
Hello,
I have a date field on a catalog form. I basically need to get the value of the date in this field and today's date and then do some calculations. However, when I log the dates, I'm getting it in the wrong format and time zone. Screenshot attached, I need the scheduled date to show in the same format as todays date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 06:13 AM
Hi Amit,
This is coming out as below. Any way of getting to show the same format as scheduled date? Should be 08/01/2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 09:38 PM
Hi @User485076
Please use below code:
var today_date = new Date();
var day = today_date.getDate();
day = day < 10 ? "0" + day : day;
var month = today_date.getMonth();
month = month + 1;
month = month < 10 ? "0" + month : month;
var year = today_date.getFullYear();
var today_date_str = day + "/" + month + "/" + year;
Thanks & Regards
Amit Verma
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:53 AM
don't use Date() class of javascript
If you are using catalog client script then pass this value to script include function via GlideAjax and then perform the calculations and return the value back to client script
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader