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 "12 Aug 2020"

<%=iDate(Now,17,0)%> will result in "Wednesday 12 August 2020"

<%=iDate(Now,18,0)%> will result in "Wednesday 12 August 2020 7:01pm"

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

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 Wednesday 12 August 2020 7:01pm
1 First day of the week (Monday) Monday 10 August 2020 7:01pm
2 Last day of the week (Sunday) Sunday 16 August 2020 7:01pm
3 First day of the month Saturday 1 August 2020 7:01pm
4 Last day of the month Monday 31 August 2020 7:01pm
5 First Sunday of the month Sunday 2 August 2020 7:01pm
6 Second Sunday of the month Sunday 9 August 2020 7:01pm
7 Third Sunday of the month Sunday 16 August 2020 7:01pm
8 Fourth Sunday of the month Sunday 23 August 2020 7:01pm
9 Last Sunday of the month Sunday 30 August 2020 7:01pm

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.