Welcome Guest ( Log In | Register )




                Web Hosting Guide

 
Reply to this topicNew Topic
Asp Date And Time Tutorial, Tutorial for the beginer
BDIT
post May 1 2008, 10:51 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: [HOSTED]
Posts: 11
Joined: 30-April 08
Member No.: 30,066


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-
[codebox]
<html>
<body>
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br />")
%>
</body>
</html>
[/codebox]
This code will display date in 5/2/2008 format.

[codebox]
<html>
<body>
<%
response.write(FormatDateTime(date(),vblongdate))
response.write("<br />")
%>
</body>
</html>
[/codebox]
This code will display date in Friday, May 02, 2008 format.

[codebox]
<html>
<body>
<%
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br />")
%>
</body>
</html>
[/codebox]
This code will display date in 5/2/2008 format.

[codebox]
<html>
<body>
<%
response.write(FormatDateTime(now(),vblongtime))
response.write("<br />")
%>
</body>
</html>
[/codebox]
This code will display date in 3:36:55 PM format.

[codebox]
<html>
<body>
<%
response.write(FormatDateTime(now(),vbshorttime))
response.write("<br />")
%>
</body>
</html>
[/codebox]
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

[codebox]
<html>
<body>
Today is <%response.write(date())%>.
<br />
</body>
</html>
[/codebox]

This code will display date in 5/1/2008 format.

[codebox]
<html>
<body>
Now <%response.write(time())%>.
<br />
</body>
</html>
[/codebox]

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.

[codebox]
<html>
<body>
<%
response.Write(WeekdayName(weekday(date)))
response.Write("<br />")
response.Write(WeekdayName(weekday(date), true))
%>
</body>
</html>
[/codebox]

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

[codebox]
<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>
[/codebox]
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.
[codebox]
<html>
<body>
<%response.write(MonthName(month(date)))%>
</body>
</html>
[/codebox]

I think, this tutorial will help the beginer. If any bug found, please informe.

Go to the top of the page
 
+Quote Post
iGuest
post Nov 20 2009, 09:35 PM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869


Capture Start & Stop of file execution
Asp 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

 

Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   18 Dream 16,316 8th March 2010 - 01:13 AM
Last post by: iG-Wuddup
No new   22 mzwebfreak 15,072 21st February 2010 - 11:44 PM
Last post by: iG-Heather
No New Posts   1 tansqrx 1,500 19th February 2010 - 08:46 PM
Last post by: iG-bob jones
No New Posts   4 Klaas 2,930 16th February 2010 - 09:11 PM
Last post by: iG-mubassir ansaro
No new   46 sPyfReEsTyLe 5,467 16th February 2010 - 03:11 AM
Last post by: levimage
No new   28 TOMORROWS GAMING 4,374 9th February 2010 - 04:35 AM
Last post by: iG-kyle kraatz
No New Posts   6 dhanesh 2,781 4th February 2010 - 10:58 AM
Last post by: iG-Sam
No New Posts 10 Snake 3,772 21st January 2010 - 08:39 AM
Last post by: iG-Fer9us0n
No New Posts   11 mimi_m 9,723 16th January 2010 - 05:00 PM
Last post by: iG-Tom Clubs
No New Posts   17 r3d 8,333 6th January 2010 - 03:29 PM
Last post by: iG-Steve
No New Posts   15 nightfox 3,529 4th January 2010 - 04:31 PM
Last post by: iG-
No New Posts   2 turbopowerdmaxsteel 7,996 4th January 2010 - 07:29 AM
Last post by: iG-v_tarasu
No New Posts   9 suicide 5,861 3rd January 2010 - 05:14 PM
Last post by: iG-arli
No New Posts   13 dhanesh 6,659 16th December 2009 - 11:02 AM
Last post by: iG-ZeN
No New Posts   1 turbopowerdmaxsteel 8,389 9th December 2009 - 10:22 AM
Last post by: iG-imran


Web Hosting Powered by ComputingHost.com.
HONESTY ROCKS! truth rules.
Creative Commons License