PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a string date in the format: dd/mm/YYYY and I want to check that against the current date. I thought I could do that by using a simple comparison using the date() function.
function str2date($in){
$t = split("/",$in);
if (count($t)!=3) return -1;
if (!is_numeric($t[0])) return -1;
if (!is_numeric($t[1])) return -2;
if (!is_numeric($t[2])) return -3;
// 2003-09-16 < -- 09/16/2003
return $t[2]."-".$t[0]."-".$t[1];
}
function date2str($in){
$t = split("-",$in);
if (count($t)!=3) return -1;
if (!is_numeric($t[0])) return -1;
if (!is_numeric($t[1])) return -2;
if (!is_numeric($t[2])) return -3;
// 2003-09-16 -- > 09/16/2003
return $t[1]."/".$t[2]."/".$t[0];
}
It works fine now... thanks... btw - I needed to retain the / format because I have a javascript calendar that provides an easier way to input the data for the user (more difficult for me )
Its because when you have it as DD/MM/YYYY and the DD starts with a 0 - like in 07/05/2003 php gets rid of that first leading zero, so it becomes 7052003 and causes havoc