SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    556
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to convert unix timestamp to specific format in mysql ?

    Hi,

    I am storing dates in mysql as unix timestamps. When I am doing select staments how do i get that unix timestamp converted to this format ?

    Format is: yyyy-MM-dd HH:mm:ss

    Thanks.

  2. #2
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    936
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You would use DATE_FORMAT() ie: SELECT DATE_FORMAT(date,format) FROM tblname.

    http://www.w3schools.com/sql/func_date_format.asp

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by eruna View Post
    You would use DATE_FORMAT()
    that's not enough -- you also have to convert the unix timestamp to a datetime value

    you could nest FROM_UNIXTIME inside DATE_FORMAT, but luckily, FROM_UNIXTIME also accepts a format string, so you could just use it by itself
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    556
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    that's not enough -- you also have to convert the unix timestamp to a datetime value

    you could nest FROM_UNIXTIME inside DATE_FORMAT, but luckily, FROM_UNIXTIME also accepts a format string, so you could just use it by itself
    Hi,

    FROM_UNIXTIME did the trick.

    Thanks.


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
  •