SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Formatting date/time from mySQL

    hi!

    I have a datetime field in a mysql database. By default it is formatted as Y-m-d H:i:s.

    When I query the database for the date, I would like to reformat it before displaying it in the browser. I would like to write it like:

    This page was last updated at H:i on d-m-Y

    How can I do this please?

    Thank you!

  2. #2
    SitePoint Enthusiast jcarouth's Avatar
    Join Date
    Sep 2006
    Location
    College Station, TX
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have a couple options

    1) use the mysql function date_format to format the column in the select query like this
    Code:
    select
       date_format(your_col, '%H:%i on %d-%m-%Y') as your_col_formatted
    from your_table
    2) select the column as a unix timestamp and use php's date function to format the date
    Code:
    select
       unix_timestamp(your_col) unix_timestamp_of_your_col
    from your_table
    and then use it
    PHP Code:
    $date date('H:i on d-m-y'$row['unix_timestap_of_your_col']); 

  3. #3
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent! Cheers jcarouth!


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
  •