Re: Date validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 On Friday, May 20, 2011, Peter Lind wrote:

>> This is pretty much as expected except that the second call to
>> date() - i.e. date('d M Y', $date) - outputs nothing.

> date() takes an int as second parameter - a timestamp. Not an object.
> And from a quick test it doesn't look like DateTime has a __toString
> method.

Thanks - my misunderstanding. I'll have to look into that further.

>> Also, AFAICT createFromFormat fails if the date is not formatted
>> according to the first parameter. So, for example:
>>  $date = DateTime::createFromFormat('d M Y', '5/2/10')
>> fails ... (at least, it does on my system :( )
>>

> I'm sorry for asking but what did you expect?? You're specifically
> calling a method that parses a string according to a given format. If
> it parsed the string according to any other format, that would be a
> huge WTF.

Don't feel sorry to have asked, because it's exactly what I expected.
João suggested using createFromFormat. Since I need to validate dates
input in any valid form, I felt it wouldn't work and my comment was to
João to that effect. That said, I've seen some weird and unexpected
results from my development server recently (e.g. my post of 16 May re
weird cookie behaviour) which was why I added the proviso "(at least,
it does on my system)" just in case that method wasn't meant to behave
as I inferred.

With all that said, I still have no 'out of the box' method to
validate a user-input date string and I haven't been able to find the
code I used with PHP 3.something before my sojourn into the depths of
ASP to know how I used to do this!

-- 
Geoff


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux