- 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:53 AM
Hi,
In the UI page client script also you can invoke GlideAjax
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:26 AM
Here is your answer
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
- 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:)