Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
|
Do you need to solve this in the db, or in php?
1)
in php: mktime() allows you to do time addition/substractions. You can specify negative value, like
PHP Code:
mktime (date("H"), date("i"), date("s"), date("n"), date("j"), date("Y")-1)
But I recommand you to do this in the db directly...
in db: Well, for that, it depends your db schema.
If you have 1 table with the articles and 1 with the sales, joined on articles.artId=sales.artFk:
Code:
select a.artId as articleId, count(a.artId) as nbrSales
from articles a
inner join sales s
on s.artFk=a.artId
where s.dtmSold between now()-interval 1 year and now()
group by a.artId
2)
in php: well, it's much more complicated, and I recommand you the db solution... Again... (Hey, I'm a db guy by trade!)
in db: Using last query as reference it would be
Code:
select last_day(s.dtmSold)+interval 1 day+interval 14 month as dtmExpiry
from sales s
__________________
Only a biker knows why a dog sticks his head out the window.
|