Print Page | Close Window

Date format - How to display date only?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=16126
Printed Date: 30 March 2026 at 3:25am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Date format - How to display date only?
Posted By: Naigewron
Subject: Date format - How to display date only?
Date Posted: 06 August 2005 at 9:52pm
Hey!

I have a site set up where I fetch the news out of a specified forum, and the news date is the Start_date of the thread. However, the posted date currently shows up as "mm/dd/yyyy hh:mm:ss", whereas I'd like to have it in some sort of long format (e.g. August 7, 2005) and without the time (only the date).

The date is fetched from the Access database, so it will first need to be converted from a string to some sort of date variable, right? And what happens after that? All I can find online about formatting is how to change the date from US to normal date format (and I can't even get that to work, presumably because the date as fetched from Access is of the wrong type).

Any help appreciated. Thank you!

Here is the code I use right now:


<!-- ASP code to fetch news -->
<%
sql="select Subject, Start_date, Topic_ID from tblTopic where Forum_ID=2 order by Start_date desc"
set rsTopic = DBConn.Execute(sql)
                                                                        rsTopic.MoveFirst()

if err.number=0 then
  while (not rsTopic.EOF)
%>

    <!-- Subject -->
    <b><% =rsTopic("Subject") %></b><br>

    <!-- Date -->
<%
    set newsdate = rsTopic("Start_date")
%>
    Posted on <% =newsdate %><br>

<%
    sql="select Message from tblThread where Topic_ID=" & rsTopic("Topic_ID")
    set rsThread = DBConn.Execute(sql)
    rsThread.MoveFirst()
%>

    <!-- News item -->           
    <% =rsThread("Message") %><br>
    <br>
    <br>
    <br>

<%
    rsTopic.MoveNext()
  wend

else
%>
  An error has occured
<%
end if
%>

<%
rsThread.close()
rsTopic.close()
DBConn.close
set DBConn=Nothing
%>




Replies:
Posted By: dpyers
Date Posted: 07 August 2005 at 12:46am
use IsDate to determine if a string or expression can be converted to a date.
Use CDate to convert it to a date format.
Use FormatDateTime to convert to any of several different date layouts.


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Naigewron
Date Posted: 07 August 2005 at 3:16am
Ah, I see. Thanks for that, figured out the use of FormatDateTime after a bit of fiddling.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net