Stupid Form Tricks
Dates and Calendars -
Getting Any Date You Want - Autofilling Date Fields
for most browsers
This script lets you do 2 things:
1. Get today's date in 9 different date formats
2. Get a past or future date using a reference date and the desired time difference (e.g. 30 days from 12/31/2002) in 9 different date formats.
The script with all the functions is available for copying in the textarea below. It starts by setting variables with today's date, month,
and year.
var date = new Date(); var curr_dy = date.getDate(); var curr_mn = date.getMonth(); var curr_yr = date.getFullYear();
Use function todaysDate() to get, you guessed it, today's date. The function takes a numerical
argument that corresponds to a date format in function dateFormats(). The formatting options are as follows:
0 = mmddyy
1 = mmddyyyy
2 = mm/dd/yyyy
3 = mm/dd/yy
4 = yyyymm
5 = ddmmyy
6 = dd/mm/yy
7 = ddmmyyyy
8 = dd/mm/yyyy
All other dates are produced using function getNextDate(). The function takes 5 arguments : month,date,year,increment,format.
The increment should take the form of a positive or negative number and refers to the number of days before or after the date specified by the first 3 arguments. For example:
// - one day before January 1, 2004 in date format 2
getNextDate(0,1,2004,-1,2)
will produce the date 12/31/2003
Below in form name="myDates" are text inputs with dates in them. The scripts are shown beneath the text inputs.
"myDates"PXL8 2004