How convert a date from dd-mm-yy
to mm-dd-yy
below is my code
<?
$date= date('d-m-y');
echo date('m-d-Y',strtotime($date));
?>
but the result is : 09-10-2001
i need 09-01-2010
This won't work:
date('m-d-y', strtotime($the_original_date));
If you have PHP 5.3, you can do:
$date = DateTime::createFromFormat('d-m-y', '09-10-01');
$new_date = $date->format('m-d-Y');
Otherwise:
$parts = explode('-', $original_date);
$new_date = $parts[1] . '-' . $parts[0] . '-' . $parts[2];
You can do:
$input = 'dd-mm-yy';
$a = explode('-',$input);
$result = $a[1].'-'.$a[0].'-'.$a[2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With