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() |
06/02/2012 |
Time() |
14:58:55 |
FormatDateTime(sDate, 1) |
06 February 2012 |
FormatDateTime(sDate, 2) |
06/02/2012 |
FormatDateTime(sDate, 3) |
14:58:55 |
FormatDateTime(sDate, 4) |
14:58 |
Time formatting
Second(sDate) |
55 |
Minute(sDate) |
58 |
Hour(sDate) |
14 |
Date formatting
Day(sDate) |
6 |
WeekDay(sDate) |
2 |
WeekDayName(WeekDay(sDate)) |
Monday |
Month(sDate) |
2 |
MonthName(Month(sDate)) |
February |
Year(sDate) |
2012 |
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.

