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

You are welcome. I've run in to that more times than I care to admit.   FWIW, we covered a lot of this in Episode 36 of TechNow.



TechNow Episode List


Awesome, next thing on my list.



You are a ROCKSTAR!!!


samadam
Kilo Sage

Is it possible to use it in Catalog Client Scripts?



var myDate = newValue;  


var gdt = new GlideDateTime();  


      gdt.setDisplayValue(myDate);  


      var sdate= gdt.getNumericValue();


g_form.setValue("end_date",sdate);



I used On Change client script but doesnt seem to work


GlideDateTime is not an available object in client scripts. You would be better served using GlideAjax to do the processing on the server in this case.



Episodes 5, 6, and 33 of TechNow talk about client scripting and GlideAjax.



Docs: Client Scripts


Docs: GlideForm


Docs: GlideAjax  


Developer: Client Scripting Technical Best Practices Overview


TechNow Episode List