Jump to content

Help! Code to Determine date?


Morbo

Recommended Posts

Hi guys, ive been using code to extract info from a database at the end of each week, and it works fine. the only issue is i have to go in at the end of every week and change the dates before i run the code, i would love to have it automated so that it would pick up that i needed the info from the past 7 days...if that makes sense?! Any help would be awesome, thanks..

 

heres the code that im using

 

SELECT

(SUM(t1.timespent) /60) ,

(SUM(t1.timebillable) /60 ) ,

MAX(t4.title) ,

FROM_UNIXTIME(t1.dateline)

FROM swtickettimetrack AS t1

LEFT JOIN swtickets AS t2 ON (t1.ticketid = t2.ticketid)

LEFT JOIN swusers AS t3 ON (t2.userid = t3.userid)

LEFT JOIN swusergroups AS t4 ON (t3.usergroupid = t4.usergroupid)

LEFT JOIN swstaff AS t5 ON (t1.forstaffid = t5.staffid)

WHERE t1.dateline >= UNIX_TIMESTAMP('2008-07-01') and t1.dateline <= UNIX_TIMESTAMP('2008-07-31') AND t4.title<>''

GROUP BY t4.usergroupid

Link to comment
Share on other sites

Thanks! if i wanted to cahnge this to a week, it should be

 

WHERE t1.dateline >= CURDATE() and t1.dateline < DATE_ADD(CURDATE(), INTERVAL 7 DAY) AND t4.title<>''

 

should it not? Ive tried it and it doesnt seem to work

 

Thanks for the code though, its works fine

 

Cheers

Link to comment
Share on other sites

for some reason both of these sets of code are bring back results that are much older than a month or a week, some as old as 2007  ???

 

Am i doing something wrong?  Heres how the code is set out now....cheers for your help if you can give any!

 

SELECT

  (SUM(t1.timespent) /60) ,

  (SUM(t1.timebillable) /60 ) ,

  MAX(t4.title) ,

  FROM_UNIXTIME(t1.dateline)

FROM swtickettimetrack AS t1

LEFT JOIN swtickets AS t2 ON (t1.ticketid = t2.ticketid)

LEFT JOIN swusers AS t3 ON (t2.userid = t3.userid)

LEFT JOIN swusergroups AS t4 ON (t3.usergroupid = t4.usergroupid)

LEFT JOIN swstaff AS t5 ON (t1.forstaffid = t5.staffid)

WHERE t1.dateline >= CURDATE() and t1.dateline < DATE_ADD(CURDATE(), INTERVAL 1 MONTH) AND t4.title<>''

GROUP BY t4.usergroupid

Link to comment
Share on other sites

i also got the following code from a website

 

WHERE t1.dateline >= UNIX_TIMESTAMP(DATE(CONCAT(YEAR(CURDATE()),'-',MONTH(CURDATE()),'-1')))

AND t1.dateline <= UNIX_TIMESTAMP(LAST_DAY(CURDATE()))

 

but it doesnt work either

 

Im in over my head here.....

Link to comment
Share on other sites

HI thanks for that, that line of code is bringing back a syntax error 

 

"You have an error in your SQL syntax near '(FROM_UNIXTIME(t1.dateline)) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() AND' at line 13"

 

sorry but i know next to nothing about mySQL, i have only been using it for about a week

 

thanks for all your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.