Re: [PHP] DateTime wierdness
echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012)); this outputs 02-14-13 also so my guess is that it is being interpreted the same as 12/14/2012 +2 months echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs 02-14-12 which is 1/1/12 +45 days 2012/3/29 Martín Marqués martin.marq...@gmail.com Can someone explain to me this weierdness I see when using the DateTime module of PHP. Here I send 14/14/2012 which is not a valid date, and I would expect to recieve false, but instead, it looks like it wrapping to the next year, as if 14 monthas are 1 year and 2 months. That isn't what's supposed to happen, or is it? $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y', '14/14/2012')); ? |php object(DateTime)#1 (3) { [date]= string(19) 2013-02-14 13:20:22 [timezone_type]= int(3) [timezone]= string(20) America/Buenos_Aires } -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DateTime wierdness
OK. So what would be a good way to validate a date? El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com escribió: echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012)); this outputs 02-14-13 also so my guess is that it is being interpreted the same as 12/14/2012 +2 months echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs 02-14-12 which is 1/1/12 +45 days 2012/3/29 Martín Marqués martin.marq...@gmail.com Can someone explain to me this weierdness I see when using the DateTime module of PHP. Here I send 14/14/2012 which is not a valid date, and I would expect to recieve false, but instead, it looks like it wrapping to the next year, as if 14 monthas are 1 year and 2 months. That isn't what's supposed to happen, or is it? $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y', '14/14/2012')); ? |php object(DateTime)#1 (3) { [date]= string(19) 2013-02-14 13:20:22 [timezone_type]= int(3) [timezone]= string(20) America/Buenos_Aires } -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DateTime wierdness
http://www.php.net/manual/en/function.checkdate.php 2012/3/29 Martín Marqués martin.marq...@gmail.com OK. So what would be a good way to validate a date? El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com escribió: echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012)); this outputs 02-14-13 also so my guess is that it is being interpreted the same as 12/14/2012 +2 months echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs 02-14-12 which is 1/1/12 +45 days 2012/3/29 Martín Marqués martin.marq...@gmail.com Can someone explain to me this weierdness I see when using the DateTime module of PHP. Here I send 14/14/2012 which is not a valid date, and I would expect to recieve false, but instead, it looks like it wrapping to the next year, as if 14 monthas are 1 year and 2 months. That isn't what's supposed to happen, or is it? $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y', '14/14/2012')); ? |php object(DateTime)#1 (3) { [date]= string(19) 2013-02-14 13:20:22 [timezone_type]= int(3) [timezone]= string(20) America/Buenos_Aires } -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador
Re: [PHP] DateTime wierdness
actually this would work well ... compare what they send with the output of the formatdate function checkDateTime($data) { if (date('Y-m-d H:i:s', strtotime($data)) == $data) { return true; } else { return false; } } 2012/3/29 David OBrien dgobr...@gmail.com http://www.php.net/manual/en/function.checkdate.php 2012/3/29 Martín Marqués martin.marq...@gmail.com OK. So what would be a good way to validate a date? El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com escribió: echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012)); this outputs 02-14-13 also so my guess is that it is being interpreted the same as 12/14/2012 +2 months echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs 02-14-12 which is 1/1/12 +45 days 2012/3/29 Martín Marqués martin.marq...@gmail.com Can someone explain to me this weierdness I see when using the DateTime module of PHP. Here I send 14/14/2012 which is not a valid date, and I would expect to recieve false, but instead, it looks like it wrapping to the next year, as if 14 monthas are 1 year and 2 months. That isn't what's supposed to happen, or is it? $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y', '14/14/2012')); ? |php object(DateTime)#1 (3) { [date]= string(19) 2013-02-14 13:20:22 [timezone_type]= int(3) [timezone]= string(20) America/Buenos_Aires } -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador
Re: [PHP] DateTime wierdness
El día 29 de marzo de 2012 14:14, David OBrien dgobr...@gmail.com escribió: actually this would work well ... compare what they send with the output of the formatdate function checkDateTime($data) { if (date('Y-m-d H:i:s', strtotime($data)) == $data) { return true; } else { return false; } } Well, I did somethin similar... $arDate = explode(/, $nacimiento); if(!checkdate($arDate[1], $arDate[0], $arDate[2])) $nacimiento = ''; Just need to set the variable $nacimiento to the empty string if it's not a valid date. Thanks anyway, -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DateTime wierdness
2012/3/29 Martín Marqués martin.marq...@gmail.com: El día 29 de marzo de 2012 14:14, David OBrien dgobr...@gmail.com escribió: actually this would work well ... compare what they send with the output of the formatdate function checkDateTime($data) { if (date('Y-m-d H:i:s', strtotime($data)) == $data) { return true; } else { return false; } } Well, I did somethin similar... $arDate = explode(/, $nacimiento); if(!checkdate($arDate[1], $arDate[0], $arDate[2])) $nacimiento = ''; Just need to set the variable $nacimiento to the empty string if it's not a valid date. Thanks anyway, -- Martín Marqués select 'martin.marques' || '@' || 'gmail.com' DBA, Programador, Administrador -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I don't know how it came to be, but a lot of people rely on this behaviour. It does make sense if you squint at it a bit -- trust that the programmer meant what they said and deliver something useful, leave error checking up to the programmer. I'm a bit ambivalent about it, personally, but the way it's implemented does seem more flexible. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php