Is it possible through PHP to change the format of this date
Jan 1 1900 12:00AM
to
01/01/1990
mm/dd/yyy
Is it possible through PHP to change the format of this date
Jan 1 1900 12:00AM
to
01/01/1990
mm/dd/yyy
See PHP's excellent DateTime classes:-
$date = DateTime::createFromFormat('M d Y H:ia', 'Jan 1 1900 12:00AM');
echo $date->format('m/d/Y');
Or, if you are a fan of one liners:-
echo DateTime::createFromFormat('M d Y H:ia', 'Jan 1 1900 12:00AM')->format('m/d/Y');
You could parse that into a timestamp with strtotime() and then use the PHP date() function to format it.
strtotime
and strftime
are the easiest to work with.
$stamp = strtotime('Jan 1 1900 12:00AM');
echo strftime("%m/%d/%G", $stamp);
See the full strftime
documentation to output your date in any format.
No, because Jan 1 1900 1200AM is never going to equal 01/01/1990. Check you year. But if you want a simple what to convert string to time try this:
<?php
$d = 'Jan 1, 1900 12:00AM';
echo date("m/d/y",strtotime($d));
?>
I would pass this into a function first that removed the time element and then converts only the data portion.
see the date function:
//replace the time() with yours
echo date('m/d/Y', time()); // = 06/06/2013