How to get only Date value from Date/Time field in Client script?

rathikaramamurt
Giga Expert

Hi Experts,

I have a Date/Time field as below:

find_real_file.png

I only require Date to be fetched from this field using client script.

Could anyone pls help?

Thanks,

Rathika

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

My recommendation would be to parse the display value of the object. You should be able to do this with a clever split() method.



If that's not an option, use a GlideAjax operation to send the date time to the server, parse it there, convert it to a date object and send it back.



something like this. WARNING: Untested code!



var dateTimeStr = g_form.getValue('u_date_time');


var dateArr = dateTimeStr.split(' ');


var date = dateArr[0];


View solution in original post

7 REPLIES 7

nitin_kumar
Mega Guru

Hi Rathika,


You can use a javascript function called split().


Check out this link - JavaScript String split() Method


Thanks,


Nitin.



PS - Please mark Helpful, Like, or Correct Answer if applicable.


Chuck Tomasi
Tera Patron

My recommendation would be to parse the display value of the object. You should be able to do this with a clever split() method.



If that's not an option, use a GlideAjax operation to send the date time to the server, parse it there, convert it to a date object and send it back.



something like this. WARNING: Untested code!



var dateTimeStr = g_form.getValue('u_date_time');


var dateArr = dateTimeStr.split(' ');


var date = dateArr[0];


jimnicholson
Giga Guru

var datePart = g_form.getValue('dateField').split(' ')[0];



Should do the trick.


Hi All,



Thanks for the script.! That was perfect