bookmark - Asp Date And Time Tutorial Tutorial for the beginer

Asp Date And Time Tutorial - Tutorial for the beginer

 
 Discussion by BDIT with 2 Replies.
 Last Update: May 11, 2011, 7:49 pm
 
bookmark - Asp Date And Time Tutorial Tutorial for the beginer  
    
free web hosting
 
Here I will try to give you some ideas about date and time coding in ASP script. In a web site we need different type of date and time like current time, today’s date, today’s day, what month is it and this information also in different format. I will try to show you few common date and time system step by step.

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.

Thu May 1, 2008    Reply    New Discussion   


Capture Start & Stop of file executionAsp Date And Time Tutorial

How would I record the start date & time and stop date & time toand ASP page?  I want to capture the start and stop of a file download in a response.Write command.

-reply by mike

 


Fri Nov 20, 2009    Reply    New Discussion   

you need this to make it work:Asp Date And Time Tutorial

You need this to make it work:System.DateTime.Today.Without it Date and Time is undefined<%=System.DateTime.Today.Year%><%=System.DateTime.Today.TimeOfDay%>Using c#

-reply by alek


Wed May 11, 2011    Reply    New Discussion   

Quickly Post to Asp Date And Time Tutorial Tutorial for the beginer w/o signup Share Info about Asp Date And Time Tutorial Tutorial for the beginer using Facebook, Twitter etc. email your friend about Asp Date And Time Tutorial Tutorial for the beginer Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Basic Info & Download/ Installation Tutorial For Asp.net 2.0   Basic Info & Download/ Installation Tutorial For Asp.net 2.0 (1)