SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress timestamp format - why?

    What would be the reason for anyone to store a timestamp like: 2009-04-23 00:53:30 instead of a unix timestamp? It makes it unsearchable via SQL, or at least a lot harder. So why would they do this?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Because it's MySQL's timestamp format: http://dev.mysql.com/doc/refman/5.1/en/datetime.html

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :sigh: that's incredibly annoying. For it to be any good I have to use mktime.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No you don't. You can use php's strtotime() to convert to a timestamp. You can also do that in the sql query by using UNIX_TIMESTAMP(my_datetime_column). You can also do the formatting in sql with DATE_FORMAT()

    This format generally makes it easier to search and manipulate in sql. You just need to familiarize yourself with the many date functions mysql provides.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the advantage of storing it like that? Because it seems like to do any comparing an integer is by far the best way to store the data.

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Using ISO 8601 as the time format has several distinct advantages. First ISO 8601 is not limited to a specific range like a Unix timestamp. min: 1970-01-01T00:00:00Z the max: 2038-01-19T03:14:07Z. ISO 8601 is also very human and computer readable.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •