Date and time formatting
Homepage >
ASP Tutorials >
Date and time in ASP
Let's start by storing the current date and time in a variable called sDate.
<% sDate = Now() %>
Now we have the date stored in this variable, we can format it in a number of different ways:
General formatting
Date() |
19/11/2008 |
Time() |
23:48:46 |
FormatDateTime(sDate, 1) |
19 November 2008 |
FormatDateTime(sDate, 2) |
19/11/2008 |
FormatDateTime(sDate, 3) |
23:48:46 |
FormatDateTime(sDate, 4) |
23:48 |
Time formatting
Second(sDate) |
46 |
Minute(sDate) |
48 |
Hour(sDate) |
23 |
Date formatting
Day(sDate) |
19 |
WeekDay(sDate) |
4 |
WeekDayName(WeekDay(sDate)) |
Wednesday |
Month(sDate) |
11 |
MonthName(Month(sDate)) |
November |
Year(sDate) |
2008 |
So now we can display the date and time in any format we want to. In the next article we'll learn how to add time intervals to a date using the DateAdd function.

