I am building a timestamp from the date, month and year values entered by users.
Suppose that the user inputs some wrong values and the date is “31-02-2012” which does not exist, then I have to get a false return. But here its converting it to another date nearby. Precisely to: “02-03-2012”..
I dont want this to happen..
$str = "31-02-2012";
echo date("d-m-Y",strtotime($str)); // Outputs 02-03-2012
Can anyone help? I dont want a timestamp to be returned if the date is not original.
That’s because
strtotime()has troubles with-since they are used to denote phrase like-1 week, etc…Try
However
31-02-2012is not a valid English format, it should be02-31-2012.If you have PHP >= 5.3, you can use
createFromFormat: