- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2014 04:28 PM
Any javascript gurus out there that can provide a script that would set the default date in a "date" field for the prior day?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2014 09:16 AM
If you want to take the time zone into consideration, set the default value to:
For a Date field:
javascript:var gdt = new GlideDate();gdt.addDays(-1);gdt.getDisplayValue();
For a DateTime field:
javascript:var gdt = new GlideDateTime();gdt.addDays(-1);gdt.getDisplayValue();
The "getDisplayValue()" is the trick if you want to use the current user's time zone. Otherwise you will get the date in GMT, which could be an issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2014 09:15 PM
Hello Giovanni,
You can set the dictionary default value as javascript:gs.daysAgoStart(1);
Please check section 2.15 in below wiki link for more details.
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#daysAgo.28int.29
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2014 09:16 AM
If you want to take the time zone into consideration, set the default value to:
For a Date field:
javascript:var gdt = new GlideDate();gdt.addDays(-1);gdt.getDisplayValue();
For a DateTime field:
javascript:var gdt = new GlideDateTime();gdt.addDays(-1);gdt.getDisplayValue();
The "getDisplayValue()" is the trick if you want to use the current user's time zone. Otherwise you will get the date in GMT, which could be an issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2014 11:44 AM
Thanks for the quick response Jim! That second reply worked like a charm. You and all the rest of the people that support us non-java developers that have to support this platform is what makes this community so invaluable. I hope you continue to do what you do so well. Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2014 12:08 PM
You are welcome and thanks for the kind words. The Community is definitely a great place to learn and I enjoy giving back whenever I can.
I'll ask bianca.vaccarini to change this discussion to a question so that you could mark the appropriate response as the "Correct Answer". This helps others know that a valid answer was given for your question.