On 04 March 2004 04:37, Andy B wrote: > hi. > > i found strtotime and it seems to work but not quite sure if i know > how to use it right... here is my code: > <?php > $time= strtotime("third saturday january 2005"); > echo date("M/D/YY", $time); > > > > i wanted it to take the third saturday of next year (2005) > and say do this: saturday january 24?? 2005 for the output. > All I get for the output though is sat/june/20092009?? I'm sort of > confused now... > > any ideas on what the problem is?
Firstly, 'Y' is date()'s format letter for a 4-digit year -- so 'YY' outputs the 4-digit year twice. If you want a 2-digit year, the format code is 'y' Now, on to your more serious problem. strtotime() won't let you have both an absolute date and a relative date in the same string -- if you try, the absolute date alwys seems to take precedence. So hte 'third saturday' phrase in your string is completely ignored. Looking at 'january 2005': a month on its own has no particular meaning to strtotime(), since valid calendar date formats containing a literal month name either have the day number in front, or are 'month day year' or 'month day'. Only the latter of these fits your string, so we have to consider 'january 2005' as meaning the 2005th day of January, with the current year being assumed by default; by a quick estimate, the 2005th January 2004 is roughly 180 days into 2009, or somewhere near the end of June 2009 -- which, unsurprisingly, is the result you've been getting. The way to do what you want is in two steps -- first getting an absolute value for 1-Jan-2005, and then finding the third Saturday from that base date. There are probably several valid ways to do this, but here are two possibilities: strtotime('third saturday', strtotime('1 jan 2005')); strtotime('third saturday', mktime(12, 0, 0, 1, 1, 2005)); (Note: I strongly advocate using midday-ish as a base time when calculating relative dates, because of the possible adverse effects of a DST timeshift intervening if you use anything in the 00:00-03:00 range -- I'm sure dealing exclusively with January is probably fairly safe in this respect, but getting into the habit of using 12:00:00 for such calculations is just plain good practice.) 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