The CreatorCon Call for Content is officially open! Get started here.

script to set the date in a field to prior day

giovanni3
Kilo Contributor

Any javascript gurus out there that can provide a script that would set the default date in a "date" field for the prior day?

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

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.


View solution in original post

6 REPLIES 6

I have marked this discussion as a question. Feel free to mark the appropriate responses as correct or helpful!


Thanks Bianca!