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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date formats

Status
Not open for further replies.

tfstom

Programmer
Sep 28, 2002
190
US
There seems to be 2 main formats for VBScripts - "08-SEP-02" and "9/8/2002". Both seem valid with most of the date routines.

I have the following code to change from the 1st format type to the 2nd, but don't know how to do the reverse.

tom = "08-sep-02"
tom2 = cDate(tom)
response.write("tom = " & tom & "<br>tom2 = " & tom2 & "<br>")

This will give me:

tom = 08-sep-02
tom2 = 9/8/2002


Is there an easy way to do the reverse - change 9/8/2002 to 08-SEP-02?

Thanks,

Tom.
 
Well this is similar and may be modified accordingly:

To make a variable be in the format of mm/dd/yyyy (and the final line of code can be modifed for other date formats), perhaps try something like the following which you might even make into a function:

varFld = CDate(MyVariable)

intMonth = Month(varFld)
intDay = Day(varFld)
intYr = Year(varFld)

If intMonth < 10 Then
strMonth = "0" & CStr(intMonth)
Else
strMonth = CStr(intMonth)
End If

If intDay < 10 Then
strDay = "0" & CStr(intDay)
Else
strDay = CStr(intDay)
End If

strYr = Right(CStr(intYr), 4) ' And change the 4 to 2 for 2 year dates.

varFld = CStr(strMonth & "/" & strDay & "/" & strYr)


Best regards,
J. Paul Schmidt, Freelance ASP Web Consultant
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
Your function gets me the mm/dd/yyyy (which I get from the CDate function.

My question is - is there an easy way to go from mm/dd/yyyy to the dd-mmm-yy (from 4/5/2004 to 04-MAY-04)?

Thanks,

Tom.
 
Why dont this work?

MyDate = FormatDateTime(Date(),1)
 
Hi

I have got it wokring but the format is wrong, how can i make it

dd/mm/yyyy
 
To make it dd/mm/yyyy, you would just use CDate

MyVariable = "05-APR-2004"
varFld = CDate(MyVariable)

response.write("varFld = " & varFld & "<BR>")
varFld = 4/5/2004

MyDate = FormatDateTime(Date(),1)

Doesn't put it in dd-mmm-yy, it gives you "Saturday, August 9, 2002" - not what I was looking for.

Tom.
 
Formatting the Date and Time in ASP faq333-3194

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top