- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 02:16 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 08:39 PM - edited 12-07-2023 08:45 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 02:39 AM - edited 12-07-2023 02:39 AM
Hi @chandan31 ,
You can try something like this
var a = '2023-12-06 12:00:00';
a = a.split(' ');
gs.info(a[0]);
You can assign a[0] value to task description field.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 08:39 PM - edited 12-07-2023 08:45 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 09:59 PM
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