hankknight
asked on
PHP: Convert date format
Using PHP, how can I change this:
2011/03/16 08:00
to this:
03-16-2011
?
2011/03/16 08:00
to this:
03-16-2011
?
Be sure to check dates such as 2011/03/05 and 2011/05/03. strtotime() sometimes has a hard time distinguishing which format the incoming date is in.
If strtotime() doesn't get yours right, then you can pull out each piece of the date with substr().
If strtotime() doesn't get yours right, then you can pull out each piece of the date with substr().
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or, if you are a fan of conciseness,
$olddate = '2011/03/16 08:00';
$newdate=substr($olddate,5 ,2)."-".su bstr($oldd ate,8,2)." -".$year=s ubstr($old date,0,4);
$olddate = '2011/03/16 08:00';
$newdate=substr($olddate,5
$d = "2011/03/16 08:00";
echo date("m-d-Y", strtotime($d) );