# Thread: [ASP] Convert Date()

1. ## [ASP] Convert Date()

Hi everyone.

I have this date in this format input : Sat, 13 Mar 2010 18:15:00 CST
I need this output: 2010-03-13

Can someone help me?
Chevy

2. myDate = split ("Sat, 13 Mar 2010 18:15:00 CST" , " " )

if Lcase(left(trim(MyDate(2)),3)) = "jan" then Mnth = 1
if Lcase(left(trim(MyDate(2)),3)) = "feb" then Mnth = 2
if Lcase(left(trim(MyDate(2)),3)) = "mar" then Mnth = 3
'...repeat 4-12

response.write MyDate(3) & "/" & Mnth & "/" & MyDate(1)

3. thanks x your help, but your code:

Code:
```<%

myDate = split ("Sat, 13 Mar 2010 18:15:00 CST" , " " )

if Lcase(left(trim(MyDate(2)),3)) = "Jan" then Mnth = 01
if Lcase(left(trim(MyDate(2)),3)) = "Feb" then Mnth = 02
if Lcase(left(trim(MyDate(2)),3)) = "Mar" then Mnth = 03

if Lcase(left(trim(MyDate(2)),3)) = "Apr" then Mnth = 04
if Lcase(left(trim(MyDate(2)),3)) = "May" then Mnth = 05
if Lcase(left(trim(MyDate(2)),3)) = "Jun" then Mnth = 06

if Lcase(left(trim(MyDate(2)),3)) = "Jul" then Mnth = 07
if Lcase(left(trim(MyDate(2)),3)) = "Aug" then Mnth = 08
if Lcase(left(trim(MyDate(2)),3)) = "Sep" then Mnth = 09

if Lcase(left(trim(MyDate(2)),3)) = "Oct" then Mnth = 10
if Lcase(left(trim(MyDate(2)),3)) = "Nov" then Mnth = 11
if Lcase(left(trim(MyDate(2)),3)) = "Dec" then Mnth = 12

response.write MyDate(3) & "-" & Mnth & "-" & MyDate(1)

%>```
Print this 2010--13
Why?

4. Where is the date being retrieved from? Perhaps the DatePart() function might be of some use?

5. Originally Posted by cms9651
thanks x your help, but your code:

Code:
```<&#37;

myDate = split ("Sat, 13 Mar 2010 18:15:00 CST" , " " )

if Lcase(left(trim(MyDate(2)),3)) = "Jan" then Mnth = 01
if Lcase(left(trim(MyDate(2)),3)) = "Feb" then Mnth = 02
if Lcase(left(trim(MyDate(2)),3)) = "Mar" then Mnth = 03

if Lcase(left(trim(MyDate(2)),3)) = "Apr" then Mnth = 04
if Lcase(left(trim(MyDate(2)),3)) = "May" then Mnth = 05
if Lcase(left(trim(MyDate(2)),3)) = "Jun" then Mnth = 06

if Lcase(left(trim(MyDate(2)),3)) = "Jul" then Mnth = 07
if Lcase(left(trim(MyDate(2)),3)) = "Aug" then Mnth = 08
if Lcase(left(trim(MyDate(2)),3)) = "Sep" then Mnth = 09

if Lcase(left(trim(MyDate(2)),3)) = "Oct" then Mnth = 10
if Lcase(left(trim(MyDate(2)),3)) = "Nov" then Mnth = 11
if Lcase(left(trim(MyDate(2)),3)) = "Dec" then Mnth = 12

response.write MyDate(3) & "-" & Mnth & "-" & MyDate(1)

%>```
Print this 2010--13
Why?
Because you changed the format.

if Lcase(left(trim(MyDate(2)),3)) = "Jan" then Mnth =01

You need to leave the months name in lower case "jan" "feb" etc., and put quotes around the month number for the comparison and output to work correctly.

if Lcase(left(trim(MyDate(2)),3)) = "jan" then Mnth = "01"

6. Originally Posted by webber123456
Because you changed the format.

if Lcase(left(trim(MyDate(2)),3)) = "Jan" then Mnth =01

You need to leave the months name in lower case "jan" "feb" etc., and put quotes around the month number for the comparison and output to work correctly.

if Lcase(left(trim(MyDate(2)),3)) = "jan" then Mnth = "01"

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•