How to substract 60 days that from current date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 11:31 PM
Hello Everyone,
var date_time = gs.nowDateTime();
var gdt = new GlideDate();
var date = gdt.getByFormat("yyyy-MM-dd");
gs.info('Todays Date ' +date);
gs.info('Date should be 2021-02-15');
gdt.addDays(-56);
gs.info('ADD Date ' +gdt.getDisplayValue());
var ed = new GlideDateTime(gdt);
ed.addDays(-30);
gs.info('Other Date ' +ed);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 11:46 PM
Hi,
It's Consider (30 Days) in Feb.
Regards,
Vikas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 11:49 PM
Hi,
you can simply use this
var gdt = new GlideDate();
var date = gdt.getByFormat("yyyy-MM-dd");
gs.info('Todays Date ' + date);
gs.info('Date should be 2021-02-15');
var gdt1 = new GlideDateTime(date);
gdt1.addDaysUTC(-60);
gs.info('ADD Date ' + gdt1.getDate());
Output:
[0:00:00.051] Script completed in scope global: script
Script execution history and recovery available here
*** Script: Todays Date 2021-04-06
*** Script: Date should be 2021-02-15
*** Script: ADD Date 2021-02-05
60 days before today is 5th Feb so the same date came in output
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2021 12:06 AM
Hi Ankur,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2021 01:18 AM
Hi Ankur,
Is there any solution for my issue, I will explain the issue here I'm having field Week Starts On which will show dates which starts from Monday. Here I'm trying to send an email notification to the users who missed their submission of time card in past 2 months (56 Days or 8 weeks), here I'm very specific 56 Days or 8 Weeks because if I take 60 Days then it will not show correct day/date because we have 31 Days or 30 Days or 28/29 Days it will affect to get the correct date. I'm trying to trigger email notification through scheduled Job which will trigger every Monday, and it will check past 8 weeks records in the timesheet whoever missed submitting their timesheet then it will send them reminder with the specific week date but your script working fine, but it has to take that week Monday as start of the week it's taking past 8 weeks or 56 days means!
For example :
Todays Date 2021-04-08
ADD Date 2021-02-11 (-56 days from today) but here it has to show 2021-02-08(Monday of that week)
How to fetch it can you help me ?
Thanks
JRY