How to extract Date from Date/Time field

Vasu ch1
Tera Contributor

Hi,

How can I extract the date from a Date/Time field? 

In a table we have created field which have record creation date and time. Now I created another field Case Created Date  of type Date and I need to extract only the date from created field and store that in Case Created Date field. 

I tried one approach by using calculated value related list. But its not working for some corner cases.

find_real_file.png

find_real_file.png

What might be the wrong here? Is there any other approach I can do?

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

Please use the below:-


var gdt = new GlideDateTime(current.sys_created_on);

var date = gdt.getLocalDate();

 

Please mark answer correct/helpful based on impact

View solution in original post

3 REPLIES 3

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

use this syntax to get only date from DateTime field:-

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.info(gdt.getDate());

Please mark my answer as correct if it helps you.

Saurav11
Kilo Patron
Kilo Patron

Hello,

Please use the below:-


var gdt = new GlideDateTime(current.sys_created_on);

var date = gdt.getLocalDate();

 

Please mark answer correct/helpful based on impact

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Should be simple as this

var str = g_form.getValue('sys_created_on');
alert(str);
str = str.split(' ');
alert(str[0]); //this gives date
alert(str[1]); //this gives time
-Anurag