Date time issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 11:20 PM
I am trying to set the date value like this, but when I set this value in the field, it is set as '2024-04-03 03:00:00'
4 hours before value,I tied most dates and time logic, but nothing works can someone please help with the same
value = '2024-04-03 07:00:00';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:07 AM
Hi,
I tried to update a data/time field using GlideRecord and it updated as per the entered value. Can you try with the below code:
var gr = new GlideRecord('incident');
gr.addQuery('number','INC0009009');
gr.query();
while(gr.next()){
gr.u_test_date_time = '2024-01-29 01:35:00'; //Setting value for the date/time field
gr.update();
}
Please mark this reply as the solution if you find it helpful. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:10 AM - edited 01-29-2024 04:12 AM
Hi @arpitha,
Working with dates/times is always fun.
Whilst I can absolutely help you set the date/time as desired, I first want to set some context and explain some date/time fundamentals to ensure you set the correct values.
It's important to remember (and know for good reason), that all times are stored in Coordinated Universal Time (UTC) and appear globally based on the system time zone.
Importantly, however, times appear to users in their local timezone, according to their user preference settings.
This is why you see a difference between the value you are setting and what is displayed. I believe you are setting the value using the default UTC value and your user preference has a timezone which factors in the difference.
This is expected behavior.
It is highly recommended unless you are absolutely sure and comfortable working with timezones, you should always set the time in UTC.
If you step back and think about users globally, the time now based in your time zone will always be different for another user who is based in another timezone.
For example, if the date/time in the UK (GMT) is 2024-01-29 11:10:48, the time in the US East Coast (ET) is 2024-01-29 06:10:48 (-5 hours including daylight savings time). The 'Opened at' time should reflect the same relative time for everyone.
I would recommend you play around with the below script in your Dev environment in order to understand a few important factors when setting the time.
Remember, it is highly recommended the time is set UTC.
Firstly, understand your instance timezone. This is easily found either under:
- System Properties > Basic Configuration
- Scroll to the System timezone for all users unless overridden in the user's record heading
Or navigate to the sys_property: glide.sys.default.tz
(By default, the field is blank. If you have not defined a time zone for this property, America/Los Angeles is the default.)
Here's a script that you can play with (reminder in Dev or your PDI) to understand the different values with dates, as well as an example of how to set the date in a chosen timezone:
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
01-30-2024 01:08 AM - edited 02-13-2024 01:42 AM
Hi @arpitha,
Did you see my earlier response where I provided a sample script to set the time in a certain timezone?
Please take a look at my response and as I recommended, play around in your Dev or PDI environment with the timezone script functions.
@arpitha - 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