Reply
What function/ code to use to count back X number of days spanning months
Old 08-26-2009, 02:25 PM What function/ code to use to count back X number of days spanning months
Novice Talker

Posts: 12
Location: Vancouver, Bc
Trades: 0
Hi All,

I'm fairly new to PHP and really do than you in advance for any hints as to come up with a solution to these problems.

Using PHP and a MySql database.

Problem 1:

I need to come up with a way of counting back 365 number days and during that period count the number of times a specific product was purchased.

Problem 2:

Product expiry. I need to calculate the first day of the fourteenth whole month after a product was purchased..... real head scratcher.



Thanks a ton in advance.
__________________


Last edited by level510; 08-26-2009 at 03:10 PM..
level510 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-26-2009, 06:51 PM Re: What function/ code to use to count back X number of days spanning months
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-28-2009, 01:30 PM Re: What function/ code to use to count back X number of days spanning months
Novice Talker

Posts: 12
Location: Vancouver, Bc
Trades: 0
Thanks for that, I'll let you know how it turns out when I get back to that section, I put it onto the back burner when I got stumped so I'll let you know in a few days.

Thanks again
__________________

level510 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What function/ code to use to count back X number of days spanning months
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.11459 seconds with 13 queries