RE: [PHP] easy date question?
-Original Message- From: Ed Lazor [mailto:[EMAIL PROTECTED]] Sent: 29 May 2002 01:49 To: [EMAIL PROTECTED] Subject: [PHP] easy date question? How can I find out the date of the 3rd Tuesday of any given month? Thanks, To get a timestamp value: $third_tues = strtotime('tue + 2 weeks', strtotime('1-may-2002')); which you can then use date() to format however you want. Of course, if you already have a timestamp for the first of the month you can use this in place of the second strtotime() call. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] easy date question?
See the PEAR Date/Calc class. On Tue, 28 May 2002, Ed Lazor wrote: How can I find out the date of the 3rd Tuesday of any given month? Thanks, -Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] easy date question?
1. set date = 1 2. get day of 1st of month 3. if day != tuesday, set date = 10-day_num (assuming Sun = 0, Mon = 1, etc) 4. add 14 to date 5. now you have your date There's most likely a better way of doing it though -Original Message- From: Ed Lazor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 29, 2002 10:49 AM To: [EMAIL PROTECTED] Subject: [PHP] easy date question? How can I find out the date of the 3rd Tuesday of any given month? Thanks, -Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] easy date question?
I came up with a solution that I'd like to share. Could someone confirm whether it's the best approach? Thanks, -Ed - source code # ex.: GetDay (Third, Saturday, 5, 2002); function GetDay($Week, $Day, $Month, $Year) { $MonthStartDay = date(w, mktime(0,0,0,$Month,1,$Year) ) + 1; switch ($Week) { case First : $Week = 0; break; case Second : $Week = 7; break; case Third : $Week = 14; break; case Fourth : $Week = 21; break; } switch ($Day) { case Sunday : $Day = 1; break; case Monday : $Day = 2; break; case Tuesday : $Day = 3; break; case Wednesday : $Day = 4; break; case Thursday : $Day = 5; break; case Friday : $Day = 6; break; case Saturday : $Day = 7; break; } $C = 0; if ($MonthStartDay $Day) { $C = $Day - $MonthStartDay; } else if ($MonthStartDay $Day) { $C = 7 - $MonthStartDay + $Day; } return ($C + 1 + $Week); } At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote: See the PEAR Date/Calc class. On Tue, 28 May 2002, Ed Lazor wrote: How can I find out the date of the 3rd Tuesday of any given month? Thanks, -Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] easy date question?
If you want to make it a few line shorter, change if ($MonthStartDay $Day) { $C = $Day - $MonthStartDay; } else if ($MonthStartDay $Day) { $C = 7 - $MonthStartDay + $Day; } to $C = ($MonthStartDay $Day ? 7 : 0) + $Day - $MonthStartDay; or maybe $C = ($MonthStartDay $Day ? 0 : 7) + $Day - $MonthStartDay; I haven't tried either one, so it may break it... If one, or both, work, then you could combine this line with the return line -Original Message- From: Ed Lazor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 29, 2002 2:44 PM To: Rasmus Lerdorf Cc: [EMAIL PROTECTED] Subject: Re: [PHP] easy date question? I came up with a solution that I'd like to share. Could someone confirm whether it's the best approach? Thanks, -Ed - source code # ex.: GetDay (Third, Saturday, 5, 2002); function GetDay($Week, $Day, $Month, $Year) { $MonthStartDay = date(w, mktime(0,0,0,$Month,1,$Year) ) + 1; switch ($Week) { case First : $Week = 0; break; case Second : $Week = 7; break; case Third : $Week = 14; break; case Fourth : $Week = 21; break; } switch ($Day) { case Sunday : $Day = 1; break; case Monday : $Day = 2; break; case Tuesday : $Day = 3; break; case Wednesday : $Day = 4; break; case Thursday : $Day = 5; break; case Friday : $Day = 6; break; case Saturday : $Day = 7; break; } $C = 0; if ($MonthStartDay $Day) { $C = $Day - $MonthStartDay; } else if ($MonthStartDay $Day) { $C = 7 - $MonthStartDay + $Day; } return ($C + 1 + $Week); } At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote: See the PEAR Date/Calc class. On Tue, 28 May 2002, Ed Lazor wrote: How can I find out the date of the 3rd Tuesday of any given month? Thanks, -Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php