Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a date 1

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
have got a date stored in a database in the format dd/mm/yyyy. when this date is output the format becomes mm/dd/yyyy. is there anyway that i can make the date appear as it is in the database ?

All that i am doing is <%response.write objRS(&quot;NewsDate&quot;)%>

which i would have expected to just output the date as is, but alas it is not. any ideas apreciated !
 
If you store it in the database as a DATE then it is stored as the number of seconds (milliseconds) since a certain date(what it is I do not know). The date is formatted according to the local settings of you machine unless you use FormatDateTime or DatePart functions.
You might have to use:
Code:
Dim varDate
Dim strDate
varDate = CDate(objRS(&quot;NewsDate&quot;))
strDate = DatePart(vardate,&quot;d&quot;) & &quot;/&quot; & _
          DatePart(vardate,&quot;m&quot;) & &quot;/&quot; & _
          DatePart(vardate,&quot;yyyy&quot;)
 
I am using three drop down menus(day, month,year) and the user selects the date they require. when they submit this, the date is made up using:

strDate = Request.Form(&quot;day&quot;) & &quot;/&quot; & Request.Form(&quot;Month&quot;) & &quot;/&quot; & Request.Form(&quot;Year&quot;)

this makes the date as 02/05/2001, the date is being written to the db fine, but when it is output it is then that it all goes screwy, and makes the date as mm/dd/yyyy

which is weird !!?!?!
 
Insert the date into the database as a string so that your database does not format it as a date in its own date format.

kevin
 
I am not sure if Format works in ASP; But are you using VB COM layer to get your data?
If so after you retrieve it from the DB and before you send it to ASP, you could format it using the Format function.
Format(<date>,&quot;DD/MM/YYYY&quot;)
Uhgar
-- Alcohol and Calculus never mix! Do not drink and derive! --
 
References are at:
And


JohnYingling's will work good. Another option you could do is:
<%
Dim date
date = rs(&quot;dbEnteredDate&quot;)

date = Day(date) & &quot;/&quot; & Month(date) & &quot;/&quot; & Year(date)

Response.write(date)
%>


Really though, check out those links, especially the second one as it has a list of different date format functions you can use.
Hope this helps. -Ovatvvon :-Q
 
Hey if u r using a stored proc to get the date from the database then u can format the date as required in the stored proc and get it.

regards,

srinu...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top