You are here: Re: [PHP] Checking a date for validity « PHP « IT news, forums, messages
Re: [PHP] Checking a date for validity

Posted by Todd Cary on 09/09/05 01:00

Chris W. Parker wrote:
> Todd Cary <mailto:todd@aristesoftware.com>
> on Wednesday, September 07, 2005 3:39 PM said:
>
>
>> /* Is date good */
>> function is_date_good($date) {
>> if (strtotime($date) == -1) {
>> $retval = 0;
>> } else {
>> if (strpos($date, "/") > 0) {
>> $parts = explode("/", $date);
>> } elseif (strpos($date, "-") > 0) {
>> $parts2 = explode("-", $date);
>> $parts[0] = $parts2[1];
>> $parts[1] = $parts2[2];
>> $parts[2] = $parts2[0];
>
>
> Why $parts2?
>
> Just use $parts instead, like you did in the other two blocks.
>
> Change it to:
>
>
>> if (strpos($date, "/") > 0) {
>> $parts = explode("/", $date);
>> } elseif (strpos($date, "-") > 0) {
>> $parts = explode("-", $date);
>> } else {
>> $parts = explode(".", $date);
>> }
>
>
>>Is there a simplier solution?
>
>
> How about strtotime()? In your function you're pretty much only
> accepting a certain number of formats for your date already so you could
> probably go with just passing the date (in whatever format it's given)
> to strtotim() and check for a 'false' or a timestamp.
>
>
> Chris.
Chris -

That you for the helpful comments! The reason I use the strtotime() up
front is to make sure "junk" data has not been placed in the fields. My
client tests by putting "%^&#$" into fields, and that creates a problem
with their php 4.2.x but not with my 4.3.9. The strtotime() took care
of the problem...

Todd

 

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

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