- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 02:56 AM
I want to fetch Date after 6 months from todays date. I am using below code which is working fine but for the next year It is calculating 13(Jan2023), from july can someone help me with below code.
Please check dateplusone log it is giving 21-13-2022 instead of 21-01-2023
var now = new Date();
alert('now -->'+now); // now -->Thu Jul 21 2022 15:22:49 GMT+0530 (India Standard Time)
var curr = now.getDate() + '-' + (now.getMonth()+1) + '-' + now.getFullYear();
alert('curr -->'+curr); // curr -->21-7-2022
if (riskRating == 'Critical' || riskRating == 'High')
{
//dateplusOne = now.getDate() + '-' + (now.getMonth()+7) + '-' + (now.getFullYear());
alert('dateplusOne -->'+dateplusOne); // dateplusOne -->21-13-2022
}
var current_date = moment(curr, 'DD-MM-YYYY');
alert('current_date -->'+current_date); // current_date -->1658341800000
//var current_plus_one = moment(dateplusOne, 'DD-MM-YYYY');
var current_plus_one = dateplusOne; // current_plus_one -->NaN
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 04:50 AM
It is solved by adding "dateplusOne = now.setMonth(now.getMonth() + 7);"
Thanks everyone:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 03:10 AM
Hello
Please try this script
if (riskRating == 'Critical' || riskRating == 'High')
{
var gdDate = new GlideDate(),
var gdFormatted;
gdFormatted = gdDate.getByFormat("dd-MM-yyyy");
var gdtDate = new GlideDateTime(gdFormatted);
gs.info(gdtDate.addMonths(6));
}
Please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 03:50 AM
This is not working (I am writing this on UI page Client script)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 03:17 AM
Hi,
you want to add 6 months to today right?
then why not use glideAjax and use GlideDateTime methods
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
07-21-2022 03:50 AM
This is not working (I am writing this on UI page Client script)