Re: Looking for a date function : "First Monday after a certain date"
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Looking for a date function : "First Monday after a certain date"

From: Emmanuel Ayrault <emmanuel.ayrault@nospamvoila.fr>
Date: Sun Jul 31 2005 - 17:35:25 CEST

Martien van Wanrooij a écrit :

> So I decided to create two fields firstdisplaytime and lastdisplaytime and I
> made a webform where the staff can update the scheduling. Up to now
> firstdisplaytime and lastdisplaytime are updated manually but I would like
> to write such a code that both fields are calculated automatically (monday
> before and after the celebrations) unless these dates are filled in
> explicitely by the staff.
> Additional suggestions will be welcome, thanks anyway.
>

I'm afraid I don't understand all what you want to do. Could you give
some exemple with real dates of celebration and the period you want to
display them.

Otherwise, you can use strtotime to calculate the monday some weeks
before or after the current date:

<?php

echo 'Today: '.date('Y-m-d').'<br />';
echo date('Y-m-d',strtotime("-1 week last Monday")).'<br />';
echo date('Y-m-d',strtotime("last Monday")).'<br />';
echo date('Y-m-d',strtotime("Monday")).'<br />';
echo date('Y-m-d',strtotime("next Monday")).'<br />';
echo date('Y-m-d',strtotime("+1 week next Monday")).'<br />';
?>

After that, you just have to use a correct query in mysql to display the
dates you want to show between 2 limits.

Hope it can be useful.

-- 
Manu
Received on Tue Oct 18 02:06:34 2005