Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- maxim vexler
August 8, 2004, 1:17 am
rate this thread
and MySQL, 2nd ed. by David Lane, Hugh E. Williams
on chapter 9 the author give an example for age validation :
(simplified code, not a direct quote)
$dob = mktime(0,0,0, 5, 3, 1983);
if ((float)$dob > (float)strtotime("-18years"))
my question is why the type casting to float ?
after all the return type of both mktime & strtotime is int, why the
need to cast to float?
the authors emphasize this in the explanation section by "We use the
mktime() function to convert the date of birth to a large numeric Unix
timestamp value, and the strtotime() function to discover the timestamp
of exactly 18 ago. *Both are cast to a large floating number to ensure
thank you for comment's ohh & yes - hope I'm not breaking any copyright
Re: type casting to float to "ensure reliable comparison" ?
"maxim vexler <hq4ever (at) 012 (dot) net (dot) il> >" <"maxim vexler
<hq4ever (at) 012 (dot) net (dot) il> wrote in message
I don't see any need for casting. Anyone?
The author's use of a Unix timestamp to store a birthday makes me suspect
his experience with PHP. It is rather well known that mktime() on PHP-Win32
can't handle dates before 1970. The code would still work, but for a book,
it is a poor example.