php - Convert date to given format from input -


this question has answer here:

i need convert given date stored in database format. have been trying google can't working.

the format input: d-j-y ( 06-16-2015 )

the format converted in: f j, y (june 16, 2015)

the code have been trying 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 $date: string(10) "06-16-2015"
  • var_dump $old_date: string(9) "01-1-1970"
  • var_dump $new_date: string(15) "january 1, 1970"

edit duplicate question

the duplicate question marked has solution fix this, feel test case of wordpress users having same issue ..

found solution, in case needs it:

$date   = get_post_meta( $post_id, 'timeline_event_date', true );  $parsed = date_parse_from_format('n-d-y', $date);  $old_date_timestamp = mktime(         $parsed['hour'],          $parsed['minute'],          $parsed['second'],          $parsed['month'],          $parsed['day'],          $parsed['year'] );  $new_date = date('f j, y', $old_date_timestamp); 

basically, code converts string proper date format.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -