Tuross Head, New South Wales, Australia

iDate function for Classic ASP

Introduction

The iDate Function is a Classic ASP function that can be used to format dates on your web page.

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 "22 Feb 2020"

<%=iDate(Now,17,0)%> will result in "Saturday 22 February 2020"

<%=iDate(Now,18,0)%> will result in "Saturday 22 February 2020 11:37pm"

<%=iDate(Now,100,0)%> will result in "2020-02-22 23:37:49.929", 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 22 Feb 2020 23:37:49
1 d Mmm YYYY 22 Feb 2020
2 d Mmm YYYY h:mmam/pm 22 Feb 2020 11:37pm
3 d Mmm YYYY hh:mm 22 Feb 2020 23:37
4 Ddd d Mmm YYYY Sat 22 Feb 2020
5 Ddd d Mmm YYYY h:mmam/pm Sat 22 Feb 2020 11:37pm
6 Ddd d Mmm YYYY hh:mm Sat 22 Feb 2020 23:37
7 Dddd d Mmm YYYY Saturday 22 Feb 2020
8 Dddd d Mmm YYYY h:mmam/pm Saturday 22 Feb 2020 11:37pm
9 Dddd d Mmm YYYY hh:mm:ss Saturday 22 Feb 2020 23:37
10 d Mmmm YYYY 22 February 2020 23:37:49
11 d Mmmm YYYY 22 February 2020
12 d Mmmm YYYY h:mmam/pm 22 February 2020 11:37pm
13 d Mmmm YYYY hh:mm 22 February 2020 23:37
14 Ddd d Mmmm YYYY Sat 22 February 2020
15 Ddd d Mmmm YYYY h:mmam/pm Sat 22 February 2020 11:37pm
16 Ddd d Mmmm YYYY hh:mm Sat 22 February 2020 23:37
17 Dddd d Mmmm YYYY Saturday 22 February 2020
18 Dddd d Mmmm YYYY h:mmam/pm Saturday 22 February 2020 11:37pm
19 Dddd d Mmmm YYYY hh:mm Saturday 22 February 2020 23:37
20 Not used  
21 Ddd Sat
22 Dddd Saturday
23 d 22
24 dd (preceeding zero) 22
25 m 2
26 mm (preceeding zero) 02
27 Mmm Feb
28 Mmmm February
29 YYYY 2020
30 Not used Empty cell
31 d/m/YYYY 22/2/2020
32 dd/mm/YYYY 22/02/2020
33 dd-mm-YYYY 22-02-2020
34 YYYY-mm-dd 2020-02-22
35 ddmmYYYY 22022020
36 YYYYmmdd 20200222
37-40 Not used  
41 h (12 hour) 11
42 hh (24 hour) 23
43 m 37
44 mm (preceeding zero) 37
45 s 49
46 ss (preceeding zero) 49
47 h:mmam/pm 11:37pm
48 h:mm:ssam/pm 11:37:49pm
49 hh:mm 23:37
50 hh:mm:ss 23:37:49
51 hhmm 2337
52 hhmmss 233749
53-60 Not used Empty cell
61 Integer 43883
62 Decimal 43883.9845949074
63 Milliseconds (ttt) (preceeding zeros) 945
64 Milliseconds (t) 945
65-98 Not used Empty cell
99 YYYY-mm-dd hh:mm:ss 2020-02-22 23:37:49
100 YYYY-mm-dd hh:mm:ss.ttt 2020-02-22 23:37:49.945

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 Saturday 22 February 2020 11:37pm
1 First day of the week (Monday) Monday 17 February 2020 11:37pm
2 Last day of the week (Sunday) Sunday 23 February 2020 11:37pm
3 First day of the month Saturday 1 February 2020 11:37pm
4 Last day of the month Saturday 29 February 2020 11:37pm
5 First Sunday of the month Sunday 2 February 2020 11:37pm
6 Second Sunday of the month Sunday 9 February 2020 11:37pm
7 Third Sunday of the month Sunday 16 February 2020 11:37pm
8 Fourth Sunday of the month Sunday 23 February 2020 11:37pm
9 Last Sunday of the month Sunday 23 February 2020 11:37pm

Code

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

License

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.