asp date format question

L

Lin Ma

In my asp page, I have a date value from SQL database and I would like to be
formatted like: yyyy,mm,dd.

Such as 1/22/2005 to be 2005,1,22

Is there a simple command I can use?

Thanks,


Lin
 
M

McKirahan

Lin Ma said:
In my asp page, I have a date value from SQL database and I would like to be
formatted like: yyyy,mm,dd.

Such as 1/22/2005 to be 2005,1,22

Is there a simple command I can use?

Thanks,


Lin

Will this help? Watch for word-wrap.

strDAT = { your SQL database date }

strDAT = DatePart("yyyy",strDAT) & "," & DatePart("d",strDAT) & "," &
DatePart("m",strDAT)

Note that "mm/dd/yyyy" format may be confusing and that "yyyy/mm/dd" is
preferred.
 
D

dlbjr

Just for fun and faster

Function MyDateFormat(d)
a = Split(d,"/")
If IsArray(a) Then
MyDateFormat = a(2) & "," & a(0) & "," & a(1)
End If
End Function

'dlbjr
'Pleading sagacious indoctrination!
 
D

Dave Anderson

Lin said:
In my asp page, I have a date value from SQL database and I would
like to be formatted like: yyyy,mm,dd.

Such as 1/22/2005 to be 2005,1,22

That is not an example of yyyy,mm,dd format, as you are suppressing leading
zeroes.


Is there a simple command I can use?

If you *really* want yyyy,mm,dd format, then you could let SQL do it, for
one thing. Using date format 102, you can force the output into yyyy.mm.dd,
then replace '.' with ',':

SELECT REPLACE(CONVERT(CHAR(10),GETDATE(),102),'.',',')

http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp
http://msdn.microsoft.com/library/en-us/tsqlref/ts_ra-rz_76lh.asp



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top