Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    136
    Thanks
    0
    Thanked 0 Times in 0 Posts

    formatting time that was VARCHAR

    My end result is that the date and time displayed on the page is like:
    PHP Code:
    Aug212007 6:43 pm 

    The problem is that the date and time is being sent and stored as VARCHAR in the format of:
    PHP Code:
    18:44:01 Aug 212007 PDT 

    I have gotten as far as:
    PHP Code:
    SELECT STR_TO_DATE(date_completed,'%H:%i:%s %b %e, %Y') as mydate 
    Now I have been really stuck on how to get it to the desired format. I have tried the following but am getting a totally wrong output with a year of 1970:

    PHP Code:
    $compDate date('F Y h:i:s A' ,$rOrders['mydate']);
    echo 
    $compDate
    What am I doing wrong?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    This may sound like a smart aleck answer but you should just bite the bullet and convert your column to a datetime type field. All your formatting problems will go away and your life will be pure bliss forever.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    How about exploding it into space separated values? 18:44:01 Aug 21, 2007 PDT

    Becomes an array with 5 elements. 18:44:01 | Aug | 21, | 2007 | PDT
    Leonard Whistler

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    the date you're passing in isnt a timestamp. Try using strtotime() on the value that comes out of the db to convert it into a timestamp before passing it into the date() function


  •  

    Posting Permissions

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