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() |
07/09/2010 |
Time() |
08:26:22 |
FormatDateTime(sDate, 1) |
07 September 2010 |
FormatDateTime(sDate, 2) |
07/09/2010 |
FormatDateTime(sDate, 3) |
08:26:22 |
FormatDateTime(sDate, 4) |
08:26 |
Time formatting
Second(sDate) |
22 |
Minute(sDate) |
26 |
Hour(sDate) |
8 |
Date formatting
Day(sDate) |
7 |
WeekDay(sDate) |
3 |
WeekDayName(WeekDay(sDate)) |
Tuesday |
Month(sDate) |
9 |
MonthName(Month(sDate)) |
September |
Year(sDate) |
2010 |
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.

