Re: Quick ? ... how come this doesn't work?

From: Date: Wed, 02 Jul 2003 19:19:09 +0000
Subject: Re: Quick ? ... how come this doesn't work?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-153763@lists.php.net to get a copy of this message
On Wednesday 02 July 2003 22:37, Anthony wrote: Please use a descriptive subject! > I'm trying to get the 1st and last day of the current week. I ty to do > this: > $startofweek = date("Y-m-d",mktime (0,0,0,date("m") > ,date("d")-date("w"),date("Y"))); > $endofweek = date("Y-m-d",mktime (0,0,0,date("m") > ,date("d",strtotime($startofweek))+6,date("Y"))); > echo $startofweek." --- ".$endofweek; > > $startofweek is correct, but if you run it for a week that has it's > beginning date in an other month (like this week), the $endofweek is in > the wrong month. What gives? If I change -date("w") to -1 or anything > else that stays within the current month, it works. What do you think? Is > there a better way to do this? Something simple like this ought to work: echo strftime('%Y-%m-%d', strtotime ("Sunday")), "\n"; echo strftime('%Y-%m-%d', strtotime ("last Monday")), "\n"; For the first day of the week you may need to check whether it is already a Monday (or Sunday depending on your conventions). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* Afternoon very favorable for romance. Try a single person for a change. */

« previous php.general (#153763) next »