Results 1 to 5 of 5

Thread: SQL Command for UNIX Date conversion?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default SQL Command for UNIX Date conversion?

    I have a table with email addresses and dates in UNIX time-from-epoch format. As these are unintelligible to me, I would like to convert them to yyyymmdd. So if the table has 3 columns: email, UNIXdate, newdate, does anyone know the correct command to use to convert the UNIX dates? I'm thinking something like this:

    UPDATE `tablename` SET `newdate` = DATE_FORMAT(`UNIXdate`, yyyymmdd);

    I just guessed at the last part. Please correct me. Thanks. e

  2. #2
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Solution

    I figured this out myself. In case anyone else needs to convert UNIX dates, this is how I did it:

    UPDATE `tablename` SET `newdate` = FROM_UNIXTIME( `UNIXDate` );

    Hope that helps somebody out there. e

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    they are indeed not human readable, however they offer the ability to easily convert or display in any type of format you wish using your server-side language... example

    Code:
    1212420466
    can be represented as

    Code:
    Jun 2, 2008 11:27am
    or

    Code:
    6/2/08 11:27
    or

    Code:
    2nd June 2008 11:27AM
    very easily in php, because you take the date format in unix time, and using a pre-determined set of variables and the date() function you can display it those few and MANY MANY other ways without having to go through a whole new set of conversions from a "human-readable" format to unix then back to whatever format you wish to use.

  4. #4
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear B: Yes, I can see how that format would probably be more efficient internally, but I like to work hands-on with the data in the databases and I find it reassuring to see at a glance what is going on with the data. I trust my eyes more than my php haha. e

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    thats what php.net is for?

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
  •