You are here: Re: Date manipulation PLEASE « PHP Programming Language « IT news, forums, messages
Re: Date manipulation PLEASE

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация