Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How convert a date from dd-mm-yy to mm-dd-yy

Tags:

date

php

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

like image 487
Testadmin Avatar asked Sep 01 '10 06:09

Testadmin


2 Answers

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];
like image 192
jasonbar Avatar answered Nov 09 '22 02:11

jasonbar


You can do:

$input = 'dd-mm-yy';
$a = explode('-',$input);
$result = $a[1].'-'.$a[0].'-'.$a[2];                                      
like image 36
codaddict Avatar answered Nov 09 '22 02:11

codaddict