- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 06:47 AM
Hi Team,
I have 2 date field start date and end date,
end date populate automatically according to start date and adding 15 days in end date accordingly start date.
I have written one script but I am unable to convert it into DD/MM/YYYY format.
var start_date = this.getParameter('sysparm_start_date');
var two_weeks_from_now = new GlideDateTime(start_date);
two_weeks_from_now.addDays(15);
return two_weeks_from_now;
From above script I am getting date in DD-MM-YYYY but I want date in DD/MM/YYYY format.
Can Somebody help me here please.?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 10:35 AM
Try this:
var start_date = this.getParameter('sysparm_start_date');
var two_weeks_from_now = new GlideDateTime(start_date);
two_weeks_from_now.addDays(15);
//Now lets format it
var format = 'dd/MM/yyyy hh:mm:ss'.split(' ');
var gdt = new GlideDateTime(two_weeks_from_now);
var formatDate = format[0];
var formatTime = format[1];
var gd = gdt.getLocalDate().getByFormat(formatDate);
var gt = gdt.getLocalTime().getByFormat(formatTime);
var output = gd + ' ' + gt;
return output;
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 07:02 AM - edited 05-08-2023 07:03 AM
This post on the community should be able to assist with this:
Since getByFormat function doesn't work for GlideDateTime, you have to do some other work to achieve what you are looking for.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 09:22 AM
Hi Steven,
Thanks for response.
I have tried but not getting successful.
Can you help me with code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 09:39 AM
Can you paste the code you have now?
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 10:35 AM
Try this:
var start_date = this.getParameter('sysparm_start_date');
var two_weeks_from_now = new GlideDateTime(start_date);
two_weeks_from_now.addDays(15);
//Now lets format it
var format = 'dd/MM/yyyy hh:mm:ss'.split(' ');
var gdt = new GlideDateTime(two_weeks_from_now);
var formatDate = format[0];
var formatTime = format[1];
var gd = gdt.getLocalDate().getByFormat(formatDate);
var gt = gdt.getLocalTime().getByFormat(formatTime);
var output = gd + ' ' + gt;
return output;
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven