SQL Report - Only Date Deliminators

SQL Report - Only Date Deliminators

by Brenda Farrell -
Number of replies: 2

This is the report I need - but I want to only select records after a given date - so that I'm not getting the entire history everytime.  Any ideas on how to do this - I've tried  Where gg.timemodified >= '2014-09-25'  -- I'm wondering if it is a UNIX Time thing - any help would be GREATLY Appreciated


SELECT u.firstname AS 'First' , u.lastname AS 'Last', CONCAT(u.firstname , ' ' , u.lastname) AS 'Display Name', 

c.fullname AS 'Course', 

cc.name AS 'Category',

CASE 

  WHEN gi.itemtype = 'course' 

   THEN CONCAT(c.fullname, ' - Total')

  ELSE gi.itemname

END AS 'Item Name',

 

ROUND(gg.finalgrade,2) AS Grade,

FROM_UNIXTIME(gg.timecreated) AS TIME

 

FROM mdl_course AS c

JOIN mdl_context AS ctx ON c.id = ctx.instanceid

JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id

JOIN mdl_user AS u ON u.id = ra.userid

JOIN mdl_grade_grades AS gg ON gg.userid = u.id

JOIN mdl_grade_items AS gi ON gi.id = gg.itemid

JOIN mdl_course_categories AS cc ON cc.id = c.category

 

WHERE  gi.courseid = c.id AND gg.timecreated is not NULL

ORDER BY lastname

Average of ratings: -
In reply to Brenda Farrell

Re: SQL Report - Only Date Deliminators

by Peter Bowen -

Hi Brenda,

The dates are stored as UNIXTIME - so the best way, is convert the date to the rime you need.

http://www.onlineconversion.com/unix_time.htm

This will let you input a date, and it will output the UNIX time, which you can put into your code.

Another thought is to add the Date filter, this gives you the option of what dates you want to look at without going into the code.

A third option, is always display only the latest 30 days, etc. The code for this would be...

gg.timecreated>(UNIX_TIMESTAMP(DATE_ADD(CURDATE(),INTERVAL -30 DAY)))


Hope this helps

Cheers

Peter


Average of ratings: Useful (1)
In reply to Peter Bowen

Re: SQL Report - Only Date Deliminators

by Brenda Farrell -

Thank you!  I converted the time stamp and got exactly what I wanted!  Thanks again!

Brenda