Re: getting timestamp for first day of current week
| From: | Olav Mørkrid | Date: | Sat, 07 Jul 2007 13:55:44 +0000 |
| Subject: | Re: getting timestamp for first day of current week | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258458@lists.php.net to get a copy of this message | ||
what i need is that "monday" means "monday this week", regardless of
whether i ask on monday, tuesday, wednesday, thursday, friday,
saturday or sunday.
the way php works now, i have to something like this:
if(date("l") == "monday")
$from = date("Y-m-d"); // if today if monday, just give today's date
else
$from = date("Y-m-d", strtotime("last monday")); // when asking on
tuesday thru sunday
it would be nice if strtotime understood the form "monday this week".
On 04/07/07, Robert Cummings <robert@interjinn.com> wrote:
On Wed, 2007-07-04 at 22:14 +0200, Olav Mørkrid wrote: On 03/07/07, Robert Cummings <robert@interjinn.com> wrote:If that's ALWAYS the case then it sounds like you have all the information you need to get the Monday you want :)what do you mean? php clearly makes a mistake in giving monday of the current week. I don't see how you figure "clearly makes a mistake". For instance the following script illustrates a VERY clear behaviour that doesn't seem mistaken to me, it seems more like a design choice: <?php$days = array ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', );foreach( $days as $day ) { echo date( 'Y-m-d', strtotime( $day ) ).' ('.$day.")\n"; }?> You'll notice that it always presents the first such date from TODAY ONWARDS. With that in mind it is trivial to get the date YOU want. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn || also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. |`------------------------------------------------------------'