Moron Posted August 17, 2006 Share Posted August 17, 2006 This code:[quote]<?php$lastjuly = strtotime("Last July 1");echo $lastjuly;echo date("m/d/Y", $lastjuly);?>.....returns the UNIX timestamp and 06/29/2001 :oAnybody know why?Now, if I change it to read "Last Monday," it returns 08/14/2006, so it works, but what's wrong with my syntax? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 17, 2006 Share Posted August 17, 2006 because you are echoing both the timestamp and the the formatted version? Quote Link to comment Share on other sites More sharing options...
Moron Posted August 17, 2006 Author Share Posted August 17, 2006 [quote author=GingerRobot link=topic=104630.msg417415#msg417415 date=1155825752]because you are echoing both the timestamp and the the formatted version?[/quote]Yes, but that's deliberate. Since I'm a total newbie, I tend to echo WAY too many things to see what I'm doing. :DThe problem is that the formatted version should be giving me 07/01/2006, since that was the [i]last July 1[/i] that happened. Instead, it's giving me 06/29/2001.See what I mean?Thanks! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 17, 2006 Share Posted August 17, 2006 Oh i see, sorry. I guess the string is not explicit enough. You could try last 01 July or something, but again, that might be too ambiguous.You could try:[code]<?php$month = date('m');if($month >= 6){$year = date('Y');}else{$year = date('Y') -1;}$lastjuly = strtotime("01 July $year");echo $lastjuly;echo date("m/d/Y", $lastjuly);?>[/code] Quote Link to comment Share on other sites More sharing options...
Moron Posted August 17, 2006 Author Share Posted August 17, 2006 [quote author=GingerRobot link=topic=104630.msg417425#msg417425 date=1155826271]Oh i see, sorry. I guess the string is not explicit enough. You could try last 01 July or something, but again, that might be too ambiguous.You could try:[code]<?php$month = date('m');if($month >= 6){$year = date('Y');}else{$year = date('Y') -1;}$lastjuly = strtotime("01 July $year");echo $lastjuly;echo date("m/d/Y", $lastjuly);?>[/code][/quote]Yep, that works. It seems to be a derivation of the "fiscal year" code you posted.Outstanding!And thanks. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.