0

How can I output my Unix timestamps to human readable GMT?

SELECT
      category
      ,fullname
      ,shortname
      ,idnumber
      ,startdate
      ,visible
      ,timecreated
      ,timemodified
  ,count( my.id ) AS mydata
FROM mdl_mytable
JOIN mycontext ct ON ( ct.my = cat.id )
LEFT JOIN myjoin ra ON ( mycontext = cat.id )
WHERE ct.mynumber =10000000
GROUP BY shortname, fullname, .category
      ,.idnumber
      ,.startdate
      ,.visible
      ,.timecreated
      ,.timemodified
ORDER BY myorder ASC

Note: The query has been changed for security reasons.

1
  • You might need to show your actual query (at least the part with FROM_UNIXTIME)...
    – dnoeth
    Commented Jun 4, 2015 at 16:01

1 Answer 1

0

MySQL support a FROM_UNIXTIME(...) function :-)

select FROM_UNIXTIME(1433433155)

And the other way around, UNIX_TIMESTAMP

Applying it to your example, assuming timecreated and timemodified are those Unix timestamps:

SELECT
      category
      ,fullname
      ,shortname
      ,idnumber
      ,startdate
      ,visible
      , FROM_UNIXTIME (timecreated)
      , FROM_UNIXTIME (timemodified)
  ,count( my.id ) AS mydata
FROM mdl_mytable
JOIN mycontext ct ON ( ct.my = cat.id )
LEFT JOIN myjoin ra ON ( mycontext = cat.id )
WHERE ct.mynumber =10000000
GROUP BY shortname, fullname, .category
      ,.idnumber
      ,.startdate
      ,.visible
      , FROM_UNIXTIME (timecreated)
      , FROM_UNIXTIME (timemodified)
ORDER BY myorder ASC
2
  • Sorry but I was a bit quick to say yes it worked. Actually I have no clue how to integrate this with my SQL :(, it ran with no errors but the two timestamp fields I applied this too are now missing in the result set
    – james
    Commented Jun 4, 2015 at 15:58
  • Error FROM_UNIXTIME and UNIX_TIMESTAMP database.UNIX_TIMESTAMP does not exist
    – james
    Commented Jun 4, 2015 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.