Tuross Head, New South Wales, Australia

iDate function for Classic ASP

Usage

The usage is easy. After including the function script on any ASP page, you can call the function with the following usage:

<%=iDate(Date,Format,Amend)%>

Arguments

There are three arguments that must be sent to the function. They are:

  • Date (DateTime - any date you want to be formatted);
  • Format (integer - a number that corresponds with the format that you want to display the date in - see Formats below); and
  • Amend (integer - a number that corresponds with the amendment that you want to make to the date - see Amendments below).

Examples

<%=iDate(Now,1,0)%> will result in "14 Oct 2019"

<%=iDate(Now,17,0)%> will result in "Monday 14 October 2019"

<%=iDate(Now,18,0)%> will result in "Monday 14 October 2019 5:29pm"

<%=iDate(Now,100,0)%> will result in "2019-10-14 17:29:12.746", perfect for database insertion.

<%=iDate("12 Jun 2014 13:00",18,0)%> will result in "Thursday 12 June 2014 1:00pm"

Formats

No Format Result
0 d Mmm YYYY hh:mm:ss 14 Oct 2019 17:29:12
1 d Mmm YYYY 14 Oct 2019
2 d Mmm YYYY h:mmam/pm 14 Oct 2019 5:29pm
3 d Mmm YYYY hh:mm 14 Oct 2019 17:29
4 Ddd d Mmm YYYY Mon 14 Oct 2019
5 Ddd d Mmm YYYY h:mmam/pm Mon 14 Oct 2019 5:29pm
6 Ddd d Mmm YYYY hh:mm Mon 14 Oct 2019 17:29
7 Dddd d Mmm YYYY Monday 14 Oct 2019
8 Dddd d Mmm YYYY h:mmam/pm Monday 14 Oct 2019 5:29pm
9 Dddd d Mmm YYYY hh:mm:ss Monday 14 Oct 2019 17:29
10 d Mmmm YYYY 14 October 2019 17:29:12
11 d Mmmm YYYY 14 October 2019
12 d Mmmm YYYY h:mmam/pm 14 October 2019 5:29pm
13 d Mmmm YYYY hh:mm 14 October 2019 17:29
14 Ddd d Mmmm YYYY Mon 14 October 2019
15 Ddd d Mmmm YYYY h:mmam/pm Mon 14 October 2019 5:29pm
16 Ddd d Mmmm YYYY hh:mm Mon 14 October 2019 17:29
17 Dddd d Mmmm YYYY Monday 14 October 2019
18 Dddd d Mmmm YYYY h:mmam/pm Monday 14 October 2019 5:29pm
19 Dddd d Mmmm YYYY hh:mm Monday 14 October 2019 17:29
20 Not used  
21 Ddd Mon
22 Dddd Monday
23 d 14
24 dd (preceeding zero) 14
25 m 10
26 mm (preceeding zero) 10
27 Mmm Oct
28 Mmmm October
29 YYYY 2019
30 Not used Empty cell
31 d/m/YYYY 14/10/2019
32 dd/mm/YYYY 14/10/2019
33 dd-mm-YYYY 14-10-2019
34 YYYY-mm-dd 2019-10-14
35 ddmmYYYY 14102019
36 YYYYmmdd 20191014
37-40 Not used  
41 h (12 hour) 5
42 hh (24 hour) 17
43 m 29
44 mm (preceeding zero) 29
45 s 12
46 ss (preceeding zero) 12
47 h:mmam/pm 5:29pm
48 h:mm:ssam/pm 5:29:12pm
49 hh:mm 17:29
50 hh:mm:ss 17:29:12
51 hhmm 1729
52 hhmmss 172912
53-60 Not used Empty cell
61 Integer 43752
62 Decimal 43752.7286111111
63 Milliseconds (ttt) (preceeding zeros) 746
64 Milliseconds (t) 746
65-98 Not used Empty cell
99 YYYY-mm-dd hh:mm:ss 2019-10-14 17:29:12
100 YYYY-mm-dd hh:mm:ss.ttt 2019-10-14 17:29:12.746

Amendments

Amendments can be made to the date that is sent to the function. For example, you may want the first day of the week, last day of the week, first day of the month, last day of the month or the first, second, third, fourth or last day of the month.

The example below shows the result of the function if the date sent to the function is now (server time), formatted with option 18 (Dddd d Mmmm YYYY h:mmam/pm)..

No Format Result
0 No amendments - use date and time passed to the function Monday 14 October 2019 5:29pm
1 First day of the week (Monday) Monday 14 October 2019 5:29pm
2 Last day of the week (Sunday) Sunday 20 October 2019 5:29pm
3 First day of the month Tuesday 1 October 2019 5:29pm
4 Last day of the month Thursday 31 October 2019 5:29pm
5 First Sunday of the month Sunday 6 October 2019 5:29pm
6 Second Sunday of the month Sunday 13 October 2019 5:29pm
7 Third Sunday of the month Sunday 20 October 2019 5:29pm
8 Fourth Sunday of the month Sunday 27 October 2019 5:29pm
9 Last Sunday of the month Sunday 27 October 2019 5:29pm

Code

You can download the code in a zip file (4kB), containing the code and an example page.

Licence

Feel free to use and amend the code as you see fit.

Acknowledgements

Thanks to Visual Pharm for the calendar image. Downloaded from IconFinder.

Created on Tuesday 12 August 2014.