0

How to convert date format using php ?

i tried to convert from 2015-02-24 03:21:56 to Feb 24, 15 03:21:56

i tried this code but not work, How can i do ?

<?PHP
    $date = "2015-02-24 03:21:56";
    echo $new_date = date('F j, Y, g:i a', $date);
?>
peat ribersal
  • 93
  • 1
  • 7

1 Answers1

0

The problem is that you're trying to feed a text string into date(), when really it wants a Unix timestamp. So, you need to convert your input data to a Unix timestamp first, then feed that to date().

Here is the code to do what you want:

<?php
    $date = "2015-02-24 03:21:56";
    $converted = strtotime($date);
    $new_date = date('F j, Y, g:i a', $converted);
    echo $new_date;
?>
TwoStraws
  • 12,862
  • 3
  • 57
  • 71