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

Fornatted Date

Status
Not open for further replies.

areric

Programmer
Jul 13, 2003
47
0
0
US
Hey all,

Im trying to get a date in the format "MMYY"

I NEED leading 0's so for july of 2004 i need it to report 0704.

Can i do this in ASP and if so how?

thanks

 
areric,
Code:
Format(MyDate, "mmyy")
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Caveat or caution:

The returned value is TEXT, and as such, cannot be sorted or ranked like a REAL DATE.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
im getting a type mismatch on this

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'Format'
/pcorder/ShoppingCart/checkout.asp, line 99

DO i need to generate MyDate somehow
maybe

i tried
Dim MyDate
MyDate = date()
MyDate=Format(MyDate, "mmyy")

i also tried just Format(MyDate, "mmyy")

both give errors.

 
because you DO have a type mismatch.

First you implicitly declare MyDate as a REAL DATE
MyDate = date()

THEN you attempt to assign a TEXT STRING to your DATE
MyDate=Format(MyDate, "mmyy")

[red]TILT![/red]

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
ok.... so how do i fix it.

Ive been looking at all the documentation i can find on this Format function and it deffinatly returns a string

even when i use to variables

MyDate = Now()
and
TheDate = Format(MyDate, "mmyy")

it still type mismatches.

I need to be able to append whatever the format function returns to another string.

Thanks again
 
also side note, format is a VB function not a vbs function, unless you have some tricks enabled server side, you wont be able to use the standard "format" function.

[thumbsup2]DreX
aKa - Robert
 
could always use datepart then rip the last half of the year off:
Code:
dim NewDate
NewDate = datepart("M",Date()) & "/" & right(datepart("Y", Date()), 2)

dunno might have to cstr the second datepart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top