Re: [PHP] Date Calculation Help
If the date is coming from a database, there might be a function/format already for that... And http://php.net/date may also have a format specifier for Quarter. If not, try this: $quarter = ((int) ($month / 4)) + 1; On Sat, June 30, 2007 10:14 am, revDAVE wrote: > I have segmented a year into four quarters (3 months each) > > nowdate = the month of the chosen date (ex: 5-30-07 = month 5) > > Q: What is the best way to calculate which quarter (1-2-3 or 4) the > chosen > date falls on? > > Result - Ex: 5-30-07 = month 5 and should fall in quarter 2 > > > > -- > Thanks - RevDave > [EMAIL PROTECTED] > [db-lists] > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
Well then after or before that you have to check that the month value is between 1 and 12 to make sure there's no input errors, then what if you ever want ot change the quarters yeah anway I just wanted an excuse to tell people to go low tech and use a switch, it's only 12 entries, and you could set a default. - Dan "Fredrik Thunberg" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] of course ceil( month / 3 ); -- /Thunis Don't panic. --The Hitchikers Guide to the Galaxy Fredrik Thunberg skrev: $q = ceil( month / 4 ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
of course ceil( month / 3 ); -- /Thunis Don't panic. --The Hitchikers Guide to the Galaxy Fredrik Thunberg skrev: $q = ceil( month / 4 ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
$q = ceil( month / 4 ); -- /Thunis The ships hung in the sky in much the same way that bricks don't. --The Hitchikers Guide to the Galaxy revDAVE skrev: I have segmented a year into four quarters (3 months each) nowdate = the month of the chosen date (ex: 5-30-07 = month 5) Q: What is the best way to calculate which quarter (1-2-3 or 4) the chosen date falls on? Result - Ex: 5-30-07 = month 5 and should fall in quarter 2 -- Thanks - RevDave [EMAIL PROTECTED] [db-lists] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
At 6/30/2007 08:14 AM, revDAVE wrote: I have segmented a year into four quarters (3 months each) nowdate = the month of the chosen date (ex: 5-30-07 = month 5) Q: What is the best way to calculate which quarter (1-2-3 or 4) the chosen date falls on? Result - Ex: 5-30-07 = month 5 and should fall in quarter 2 If you divide the month number by 3 you get: 1 0.3 2 0.7 3 1 4 1.3 5 1.7 6 2 7 2.3 8 2.7 9 3 10 3.3 11 3.7 12 4 The first digit is off by one, so subtract .1 from each result: 1 0.2 2 0.56667 3 0.9 4 1.2 5 1.56667 6 1.9 etc. Now you can see from the first digit that if you take the integer value and add 1 you'll get: 1 1 2 1 3 1 4 2 5 2 6 2 etc. In PHP this could be: intval(($month - .1)/3 + 1) or: intval(($month + .9)/3) I believe you can use intval() and floor() interchangeably in this circumstance. Regards, Paul __ Paul Novitski Juniper Webcraft Ltd. http://juniperwebcraft.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Date Calculation Help
I have segmented a year into four quarters (3 months each) nowdate = the month of the chosen date (ex: 5-30-07 = month 5) Q: What is the best way to calculate which quarter (1-2-3 or 4) the chosen date falls on? Result - Ex: 5-30-07 = month 5 and should fall in quarter 2 -- Thanks - RevDave [EMAIL PROTECTED] [db-lists] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php