Odd dates coming from reports

Odd dates coming from reports

by Stan Montgomery -
Number of replies: 2

Hi All,
I'm having issues where the dates being retrieved from an SQL report are displayed incorrectly. The dates are displaying several months behind what they actually are.
Any Assistance is greatly appreciated.

SELECT concat(u.firstname," ", u.lastname) AS 'name',
co.fullname AS 'Course' ,
CASE
  WHEN gi.itemtype = 'course'
   THEN concat('<strong>',co.shortname,' Course Average','</strong>')
  ELSE gi.itemname
END AS 'Item Name',
 
ROUND(gg.finalgrade,2) AS Grade,
DATE_FORMAT(FROM_UNIXTIME(gi.timemodified),'%d %M, %Y')  as DATE
 
FROM prefix_course AS co
JOIN prefix_context AS ctx ON co.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = co.category
 
WHERE  gi.courseid = co.id
%%FILTER_COURSES:co.id%%
%%FILTER_USERS:concat(u.firstname," ", u.lastname)%%
ORDER BY lastname,firstname,course,gi.timemodified DESC

 

Stan.

Average of ratings: -
In reply to Stan Montgomery

Re: Odd dates coming from reports

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am not sure I would use 'Date' as a column alias. It is probably a database reserved word.

Also, as of a recent release, the customsql report, which the block is based on, does magic handling of columns with a name ending date, so you probably do not need the DATE_FORMAT(FROM_UNIXTIME bit at all. Just call the column graded_date or something.

In reply to Tim Hunt

Re: Odd dates coming from reports

by Stan Montgomery -

Hi Tim,
Thanks for the reply.
I changed DATE to COMPLETED, and changed the gi.timemodified to gg.timemodified, and think I have the correct dates being displayed now.
I've found one other flaw in the SQL, and that is that on the grades_grade table there is no value in the timemodified column for the average course score per user.
The only time there is a value is when the module is completed and a record inserted, not the course record.
Any ideas on how I can get this information?

I am simply trying to get a record of student / course average / date from the database.
Stan.