- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 08:08 AM
I have a script that should add 3 years to a date time field. For some reason it is not working. Here is the script:
var deployed = new GlideDateTime(current.u_install_date);
gs.info("deployed: " + deployed);
var newUpgradeDate = deployed.addYearsUTC(3);
gs.info("newUpgradeDate: " + newUpgradeDate);
Output in the logs:
deployed: 2022-02-10 14:27:41
newUpgradeDate: undefined
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 08:28 AM
var deployed = new GlideDateTime(current.u_install_date);
gs.info("deployed: " + deployed);
deployed.addYearsUTC(3);
var newUpgradeDate = deployed;
gs.info("newUpgradeDate: " + newUpgradeDate);
*** Script: deployed: 2022-02-10 16:28:41
*** Script: newUpgradeDate: 2025-02-10 16:28:41
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 08:28 AM
var deployed = new GlideDateTime(current.u_install_date);
gs.info("deployed: " + deployed);
deployed.addYearsUTC(3);
var newUpgradeDate = deployed;
gs.info("newUpgradeDate: " + newUpgradeDate);
*** Script: deployed: 2022-02-10 16:28:41
*** Script: newUpgradeDate: 2025-02-10 16:28:41
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 08:35 AM
Hi JJG,
Try this:
var deployed = new GlideDateTime(current.u_install_date);
//var deployed = new GlideDateTime('2022-02-10 14:27:41'); //line for testing - remove once implemented and verified as working
gs.info("deployed: " + deployed);
deployed.addYearsUTC(3);
gs.info("deployed: " + deployed);
Output using commented line and today's date/time:
*** Script: deployed: 2022-02-10 14:27:41
*** Script: deployed: 2025-02-10 14:27:41
To help others, please mark correct and/or helpful
Thanks, Robbie