SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: [ASP] Convert Date()

  1. #1
    SitePoint Addict cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    [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?
    Thanks in advance.
    Chevy

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    659
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #3
    SitePoint Addict cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,534
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Where is the date being retrieved from? Perhaps the DatePart() function might be of some use?
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    659
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cms9651 View Post
    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. #6
    SitePoint Addict cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    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"



Bookmarks

Posting Permissions

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