I need to convert a given date already stored in database to a certain format. I have been trying to google it but can’t get it working.
The Format as Input: d-j-Y
( 06-16-2015 )
The Format to be converted in: F j, Y
(June 16, 2015)
The code I have been trying to convert,
$date = get_post_meta( $post_id, 'timeline_event_date', true );
$old_date = date('d-j-Y', $date);
$old_date_timestamp = strtotime($old_date);
$new_date = date('F j, Y', $old_date_timestamp);
var_dump(s)
:
var_dump
for$date
:string(10) "06-16-2015"
var_dump
for$old_date
:string(9) "01-1-1970"
var_dump
for$new_date
:string(15) "January 1, 1970"
EDIT For The Duplicate Question
The duplicate question you marked has the solution to fix this, but I feel this is a good test case for all of WordPress users who are having the same issue ..
Found the solution, in case someone needs it:
Basically, this code converts
string
to proper date format.