Set last day of month and time 23:59:00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 01:39 AM
Hi Team,
we have one field called due date in which we have to populate the last day of the month from the pre-hire field and the time should be 23:59:00 which should according to America/new_york time zone
suppose in the pri-hire field we have (10/02/2024) so in the due date field I want populate 29/02/2024 23:59:00 according America/new_york
I am not getting logic with script.
I am working on scoped application.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 01:20 AM
Hi @lucky24,
Can you confirm when you are checking both the native and portal UI's that you're using the same user profile (which has the same timezone settings)?
Time is a common aspect where people get confused.
Time is relative to the user's location. The difference between US East Coast time and India (Mumbai) is 10.5 hours (currently). Therefore it is impossible to set the date time to be exactly the same in both locations.
This is why IT systems and ServiceNow store time in UTC (Coordinated Universal Time).
I would set (and it is best practice) to set the time in UTC which is by default and ServiceNow will display this time relative to a user's timezone.
I've removed the timezone setting line from your original script. Use the below:
@lucky24 - To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 02:52 AM - edited 02-19-2024 02:53 AM
Hi @lucky24 ,
Try the below logic
var myDate = new GlideDateTime();//Replace with your date field name.
var daysCount = myDate.getDaysInMonthUTC();
var newDate= daysCount +'-'+myDate.getMonthUTC()+'-'+myDate.getYearUTC()+" "+"23:59:00";
var newDateTime = new GlideDateTime(newDate)
gs.info(newDateTime);
-Dhanraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 12:11 AM
Hi @lucky24,
How did you go with the updated script I provided yesterday?
Please also take note of the advice I gave around time zones.
@lucky24 - Can you please mark my solution if it works and solves your question.
Community members like myself take time
out of their day to help and providing feedback not only helps other people in the community, it recognises the contribution members make.
Updated Script:
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie