|
Posted by Kimmo Laine on 12/18/62 11:48
"Des" <desotuatail@aol.com> wrote in message
news:1148466523.938047.57880@j55g2000cwa.googlegroups.com...
> Well this kind of works. The code output i get is
>
> 2006-05-21
> 1970-01-01
>
> I don't think 1970 is the next saturday. Also I need this in a format
> suitable for an SQL Query.
>
> Des.
>
Sorry about that, and way to go with sarcasm by the way. (It always helps
when someone is trying to _help_ you and you reply sarcastically "I don't
think 1970 is next saturday"...) I first wrote the code using variable names
$dateforlastsunday but then changed them to $lastsunday etc... Except in one
critical place... :) Below is a working code with the typo fixed.
$lastsunday = date('w')==0 ? mktime() : strtotime('last sunday');
// If today _is_ sunday, then today, else last sunday
echo date('Y-m-d',$lastsunday);
$nextsaturday = strtotime('next saturday',$lastsunday);
// Next saturday counting from the given sunday.
echo date('Y-m-d',$lastsaturday);
YYYY-mm-dd is a general date format that most databases do support and since
you mentiond you can do the rest, I'm sure you'll be able to make with the
correct date format on your own.
Just in case: http://php.net/manual/en/function.date.php
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|