So i have a small issue. I am using jquery datepicker to collect dates. While users enter data, they see the following format mm/dd/yy But I would like to convert that to m-d-Y in Php.
Please help. Thanks
So i have a small issue. I am using jquery datepicker to collect dates. While users enter data, they see the following format mm/dd/yy But I would like to convert that to m-d-Y in Php.
Please help. Thanks
$date = DateTime::createFromFormat('m/d/y', $time);
echo $date->format('m-d-Y');
To "change date from m/d/Y to m-d-Y" you can just use str_replace
$date = '03/13/2013';
$date = str_replace('/', '-', $date);
If you need to change the format ie from yy
to Y
, try this:
$date = '03/13/13';
$date = date('m-d-Y', strtotime($date));
References:
$input = 'mm/dd/yy';
$a = str_replace('/', '-', $input);
echo $a; // outputs mm-dd-yy
You have a couple of options.
$incomingDate = "05/21/1979";
$newDate = date( "m-d-Y", strtotime( $date ) );
echo $newDate;