How to display date if you are receiving date and time both

chandan31
Tera Contributor

Hi All,

 

One of the requirement we are receiving date and time (like 2023-12-06 12:00:00) from the one of the field , but i want display date only in the task description .

Can you help me to get the date.

 

Thanks

1 ACCEPTED SOLUTION

abirakundu23
Mega Sage

Hi @chandan31 ,

Please use below script,

var gdt1 = new GlideDateTime("2023-12-06 12:00:00");

var gdt2 = gdt1.getDate();

gs.info ("Date is :" +gdt2);
you can set gdt2 value in task description.

Please go through below article to get more information.

GlideDateTime | ServiceNow Developers

Please mark helpful & accept correct answer if it's helpful for you. 

 

View solution in original post

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @chandan31 ,

 

You can try something like this

 

var a = '2023-12-06 12:00:00'; 
a = a.split(' ');
gs.info(a[0]);

 

 

DanishBhairag2_0-1701945519895.png

 

You can assign a[0] value to task description field.

 

Thanks,

Danish

 

abirakundu23
Mega Sage

Hi @chandan31 ,

Please use below script,

var gdt1 = new GlideDateTime("2023-12-06 12:00:00");

var gdt2 = gdt1.getDate();

gs.info ("Date is :" +gdt2);
you can set gdt2 value in task description.

Please go through below article to get more information.

GlideDateTime | ServiceNow Developers

Please mark helpful & accept correct answer if it's helpful for you. 

 

Amit Gujarathi
Giga Sage
Giga Sage

Hi @chandan31 ,
I trust you are doing great.
You can try below simple code for the same :

// Assuming 'dateTimeString' is the variable that holds your date-time value
var dateTimeString = current.your_date_time_field; // Replace 'your_date_time_field' with your field name

// Extract the date part from the string
var dateOnly = dateTimeString.split(" ")[0];

// Now you can use 'dateOnly' to set in the task description or wherever needed
current.short_description = "Date: " + dateOnly; // Example of setting it in the task's short description

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi