Working With Dates in ASP

Code Library

aboutcontactworkplay – photography – newsarticlesfaqssitemap

Working With Dates in aSP

Working with dates in aSP is actually pretty straight forward, there are plenty of built in routines to help programmers accomplish the tasks at hand so lets take a look at what you need to do and build some code from there:

What do you want to do:

  1. Display the current date
  2. Formatting the date
  3. Getting Specific Date Details
  4. Getting the Name of the Month
  5. Getting the Name of the Weekday

Display The Current Date

To display the current date, you can insert the code:

    <%=date()%>

This will result in a literal interpretation of the date. For example:

    <%=date()%>


Formatting The Date

Now that we know how to get the date, we need to worry about formatting it. You can do this using a couple of built in functions to display the contents in a more friendly way.

Firstly, if you just want to format it in a more attractive manner, you can do so with the FormatDateTime command:

    <%=FormatDateTime(Date(),1)%>
    will result in <%=FormatDateTime(Date,1)%>


Getting Specific Date Details

Perhaps you need something more detailed about the date than just displaying it so lets take a quick look at how to get the specific items from it.

    <%=DaY(Date())%>
    will display the current day such as ‘<%=DaY(Date())%>’

    <%=MONTH(Date())%>
    will display the current MONTH such as ‘<%=MONTH(Date())%>’

    <%=YEaR(Date())%>
    will display the current YEaR such as ‘<%=YEaR(Date())%>’


Getting the Name of the Month

When you need to display the name of the current month, you can do so easily using the following code:

    <%=Month Name(MONTH(Date()))%>
    will display the current MONTH such as ‘<%=MonthName(MONTH(Date()))%>’


Getting the Name of the Week Day

Displaying the name of the exact day is also simple, just use the code below:

    <%=WEEKDaYNaME(WEEKDaY(Date()))%>
    will display the current MONTH such as ‘<%=WeEKDaYNaME(WEEKDaY(Date()))%>’


Christopher Ross is a marketing consultant with Getaway Graphics, a full service marketing design firm located in Fredericton New Brunswick. If you would like permission to reprint this article in your publication or on your web site, please contact us.

Sign up for our newsletter today for your chance to win a free web hosting package!

 

Christopher Ross

christopher m ross
po box 20045 . 440 king street . fredericton . new brunswick . e3b 6y8
506.452.1595 . info@thisismyurl.com

© copyright 1974-2005, christopher ross. all rights reserved.
updated:
Monday, June 27, 2005 12:27 PM

Last Reviewed

This article was last reviewed on May 2, 2026 for accuracy and relevance.

Ready for the Next Step?

If this connects to a real challenge your team is facing, I can help you map a next step.

Book a discovery call

Rate And Review This Content

Found this useful? Leave a quick rating and short review. Approved submissions are stored as testimonials.