Copy Date field to Date Time field

samadam
Kilo Sage

I have a date field that I need to copy to a date time field. Is there a way to do this? Do I need to append the time before I copy?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

You can copy it directly. By default it will end up with a midnight value on the date from the date field. Example:



var gr = new GlideRecord('table_name');


gr.get('SYS_ID');


gr.my_date_time = gr.getValue('my_date');


gr.update();


View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

You can copy it directly. By default it will end up with a midnight value on the date from the date field. Example:



var gr = new GlideRecord('table_name');


gr.get('SYS_ID');


gr.my_date_time = gr.getValue('my_date');


gr.update();


Gaurav Bajaj
Kilo Sage

Hi, SAM,



It might work but it's better to convert your date object to GlideDateTime object first and then pass the derived value to your date/time field.



find_real_file.png




Please mark correct/helpful based on the impact of the response.




Thanks


Gaurav


Hi Gaurav,



Be cautious when using getDisplayValue() on one side of your assignment. That output as the timezone applied. The database stores values in   UTC so you've just introduced an offset error on line 8.


Thanks for the information Chuck. I checked that and you are right about it.