Date conversion help.

Discussion in 'PHP' started by kks_krishna, Jul 4, 2007.

  1. #1
    HI,

    I am getting the date from mysql as "2007-07-04 18:00:55" in this format. While displaying I want to show as "04/07/2007". How can I format like that?
     
    kks_krishna, Jul 4, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    when you get it from mysql, in your query, let mysql do the dirty work.
    
    select date_format(my_date,'%m/%d/%Y') as date from tbl1
    
    Code (markup):
     
    ansi, Jul 4, 2007 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    use the unix_timestamp function in mysql, it's better IMO

    Then in php
    strftime("time format",unix_timestamp)
    PHP:
     
    nabil_kadimi, Jul 5, 2007 IP