Welcome Guest ( Log In | Register )



 
Reply to this topicStart new 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-
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.

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Using system date in java... How?(5)
  2. How To Remove Bad Sectors Or Bad Clusters From HDD(17)
  3. 3ds Max Tutorial.(7)
  4. Task Mgr. Has Been Disabled By Your Administrator(6)
  5. C#.NET: Web Timer Control Tutorial(3)
  6. Finding Yahoo Account Creation Date(1)
  7. VB.NET: MS-Access Interaction Tutorial (Part I)(18)
  8. Using The Php Mail() Function For Images Or Attachments(3)
  9. Pre Loader Tutorial For Flash(6)
  10. Installing Glut To Dev C++(3)
  11. Wireless: Bypassing Mac Filtering(10)
  12. Phpbb - Installation Tutorial ( For Newbies Based On Astahost Cpane)l(5)
  13. Best Games Of All Time(15)
  14. Php Tutorial: Making A Shoutbox(11)
  15. Html Basic Tutorial(9)
  1. Timeshift Discussion(2)
  2. How To Download Videos From Youtube(11)
  3. Linux Beginners - Tutorial On Editors In Linux.(3)
  4. C/c++ -gdb Linux Debug Tool(1)
  5. Gimp Userbar Tutorial(3)
  6. Date Timezones.(2)
  7. Back After Long Time(1)
  8. Bulletproof Ftp Server Tutorial(0)
  9. Moving To Fedora 9(1)
  10. Basic Html Tutorial(1)
  11. Psychostats(1)
  12. How To Understand A Database Schema(4)
  13. Here Are Some Great Php Tutorial Sites(4)


 



- Lo-Fi Version Time is now: 12th October 2008 - 09:49 AM