Date & Time in ASP

Posted on 13. Nov, 2007 by in Archive 1,232 views

Remember: all of the examples of showing date and time in this tutorial show the time of a server.

That means, that, if your server is in the UK you’ll have the time that is on that server, in this case UK time.

Date

To show just date we use:

<% = date %>, which gives for instance: 15.12.2005

Time

To show just time we use:

<% = time %>, which gives for instance: 10:23:15

Now (date and time)

By using now we can show both date and time:

<% = now %>, which gives for instance: 13.12.2005 10:25:07

Ways of showing date and time

It is possible to show date and time in many ways, but we have choosen just some of the best.

Day

<% = day(now) %>

Month

<% = month(now) %>

Year

<% = year(now) %>

Names of days and months

To show which day in a week it is by number (1-7) we use:

<% = weekday(now) %>

To show a name of a day in a week we use:

<% = weekdayname(weekday(now)) %>

To show which month in a year it is by numbers we use:

<% = month(now) %>

To show a name of a month in a year we use:

<% = monthname(month(now)) %>

Hours, minutes and seconds

For hours we use:

<% = hour(now) %>

For minutes we use:

<% = minute(now) %>

For seconds we use:

<% =second(now) %>

Example:

<% response.write hour(now) & “:” & minute(now) & “:” & second(now) %>
will give: 10:39:25

2 Responses to “Date & Time in ASP”

  1. Dee

    12. Dec, 2007

    These are not ASP issues but rather VB script language issues. They would be different for Jscript.

  2. admin

    12. Dec, 2007

    Correct, but still they can be used in ASP.

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes