Question : date format incorrect

hi
i am using jquery datepicker and i have it so that it displays d-m-y. the date is appearing ok such as 26-08-2010 in the input field, but when the results are passed for processing the date seemd totally screwed up. instead say displaying 25-08-2010 it will display 12-07-21 it seems to be adding 2 years to the year? can anyone see the error in my code? it is to be inserted into mysql. thanks
1:
2:
$datepicker = date('Y/m/d', strtotime($_POST['datepicker']));
$_SESSION['datepick'] = $datepicker;

Answer : date format incorrect

Dates can be a bit of a pain - especially in the UK where we use dd mm yyyy.

You can try splitting the date on the slash and rebuilding into a format that you know strtotime will work with.


1:
2:
3:
$date_parts = explode("/",$_POST['datepicker']);
$newDate = $date_parts[2]  . "-" . $date_parts[1] . "-" . $date_parts[0];
$datepicker = date('Y/m/d', strtotime($newDate));
Random Solutions  
 
programming4us programming4us