Jump to content
xisto Community
Sign in to follow this  
Tourist

Asp Date And Time Tutorial Tutorial for the beginer

Recommended Posts

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-

<html><body><%response.write(FormatDateTime(date(),vbgeneraldate))response.write("<br />")%></body></html>

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

<html><body><%response.write(FormatDateTime(date(),vblongdate))response.write("<br />")%></body></html>

This code will display date in Friday, May 02, 2008 format.

<html><body><%response.write(FormatDateTime(date(),vbshortdate))response.write("<br />")%></body></html>

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

<html><body><%response.write(FormatDateTime(now(),vblongtime))response.write("<br />")%></body></html>

This code will display date in 3:36:55 PM format.

<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

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

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

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

This code will display time in 5:41:20 PM formatNow 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.

<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. Here1 = Sunday2 = Monday3 = Tuesday4 = Wednesday5 = Thursday6 = Friday7 = Saturday

<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 SundayMondayTuesdayWednesdayThursdayFridaySaturdayNow we will use MonthName(month(date)) to know the current month name.

<html><body><%response.write(MonthName(month(date)))%></body></html>

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

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites
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 undefinedUsing c#

-reply by alek

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.