We can use “FormatDateTime(date,format)” syntax to get current date and time. Here parameter date is any valid date expression like Date() or Now(); and the parameter “format” is a value that specifies the date/time format to use. This ‘format’ parameter is optional. You may use vbgeneraldate, vblongdate, vbshortdate, vblongtime, vbshorttime etc as ‘format’.
When I am writing this tutorial, it is Friday, May 02, 2008 in our country. If we want to display that in that format we will use vblongdate as format parameter. We may also say that today is 5/2/2008. If we want that date display as that format we will use vbshortdate as format parameter. Incase of time we may use 24 hours system or AM/PM system. If we want to use 24 hours system we will use vbshorttime as format parameter. If we want to use AM/PM system, we will use vblongtime as format parameter.
Complete ASP code for different format of date and time are given below-
CODE
<html>
<body>
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br />")
%>
</body>
</html>
This code will display date in 5/2/2008 format.
CODE
<html>
<body>
<%
response.write(FormatDateTime(date(),vblongdate))
response.write("<br />")
%>
</body>
</html>
This code will display date in Friday, May 02, 2008 format.
CODE
<html>
<body>
<%
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br />")
%>
</body>
</html>
This code will display date in 5/2/2008 format.
CODE
<html>
<body>
<%
response.write(FormatDateTime(now(),vblongtime))
response.write("<br />")
%>
</body>
</html>
This code will display date in 3:36:55 PM format.
CODE
<html>
<body>
<%
response.write(FormatDateTime(now(),vbshorttime))
response.write("<br />")
%>
</body>
</html>
This code will display date in 15:36 format.
We can also use date() and time() directly. date() will display current date and time() will display current time. The complete ASP code will be
CODE
<html>
<body>
Today is <%response.write(date())%>.
<br />
</body>
</html>
This code will display date in 5/1/2008 format.
CODE
<html>
<body>
Now <%response.write(time())%>.
<br />
</body>
</html>
This code will display time in 5:41:20 PM format
Now we will use WeekDayName(weekday(date)) to know the current day. We can display current day in short form and full form. WeekDayName(weekday(date)) will display current day in full format and WeekdayName(weekday(date), true) will display current day in Abbreviated form.
CODE
<html>
<body>
<%
response.Write(WeekdayName(weekday(date)))
response.Write("<br />")
response.Write(WeekdayName(weekday(date), true))
%>
</body>
</html>
Now we will use WeekDayName(weekday) syntax to get a week day. We will use 1, 2, 3, 4, 5, 6, 7 as weekday to display different days of the week. Here
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
CODE
<html>
<body>
<%
response.Write(WeekDayName(1))
response.Write("<br />")
response.Write(WeekDayName(2))
response.Write("<br />")
response.Write(WeekDayName(3))
response.Write("<br />")
response.Write(WeekDayName(4))
response.Write("<br />")
response.Write(WeekDayName(5))
response.Write("<br />")
response.Write(WeekDayName(6))
response.Write("<br />")
response.Write(WeekDayName(7))
%>
</body>
</html>
It will give output like this
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Now we will use MonthName(month(date)) to know the current month name.
CODE
<html>
<body>
<%response.write(MonthName(month(date)))%>
</body>
</html>
I think, this tutorial will help the beginer. If any bug found, please informe.

