SQL Report showing wrong date/time due to timezone

Re: SQL Report showing wrong date/time due to timezone

by Lee Mulvogue -
Number of replies: 2

Got an example of the sql query?  Which sql?  (eg. MySQL?)  Sounds like it's showing UTC (GMT) time.

I know PHP will use unix time and has to be compensated for, but I think(!) SQL also goes on the server time rather than the moodle system time?  So it's entirely possible to get three different times depending on which method you use?

Pretty sure all time data written to the database is in the moodle system time though.

In reply to Lee Mulvogue

Re: SQL Report showing wrong date/time due to timezone

by Juan F -

Lee, thanks for the reply.  Here's a sample SQL with the 'Due Date" and 'Open Date" are showing incorrectly.  Please note I'm not by any means an expert in SQL.  I've learned on my own.

For time, we use 24 hours..not sure if all Moodle folks use this or not.

select mc.shortname "course",
ma.name "assignment Name",
FROM_UNIXTIME( ma.duedate, '%m/%d/%Y %H:%i' ) AS "Due Date",
FROM_UNIXTIME( ma.allowsubmissionsfromdate, '%m/%d/%Y %H:%i' ) AS "Open Date"

from mdl_course mc
join mdl_course_categories mcc on mcc.id = mc.category
join mdl_course_modules mcm on mc.id = mcm.course
join mdl_modules mm on mm.id = mcm.module
join mdl_assign ma on mcm.instance = ma.id
WHERE mm.name = 'assign' 
ORDER by mc.shortname


In reply to Juan F

Re: SQL Report showing wrong date/time due to timezone

by Lee Mulvogue -

Yep pretty certain what you are seeing there is unix time converted to UTC; you'll need to do some additional stuff to get it into your local system time.

Here's a stackoverflow question with several different methods in the answers:

http://stackoverflow.com/questions/13515752/how-to-get-unix-timestamp-in-mysql-from-utc-time

Looks like maybe 'SYSTEM' or session.time_zone could give you the result you are after?  I haven't used either of these yet...  I'm also pretty-much a self-learnt (ie. googled)