0

I would like to Format my Date and time but i do not know how to at the moment i am getting a output like 2015-12-16 02:24:33 but i would like to get somthing like this 8th August 2015 03:12:46 PM how can i do this

$note_query = mysql_query("SELECT * FROM `notes` WHERE `user_id` = $my_id");
while ($run_note = mysql_fetch_assoc($note_query))
        {
          $note_date = $run_note['Note_added_dat'];
          echo $note_date;
         }
kunz
  • 1,063
  • 1
  • 11
  • 27
  • one option: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format –  Dec 16 '15 at 02:43
  • Please avoid using deprecated `mysql_*` functions, use PDO / MySQLi instead. – Raptor Dec 16 '15 at 02:47

4 Answers4

3

Try this way to format your date using php date formats.

   $note_query = mysql_query("SELECT * FROM `notes` WHERE `user_id` = $my_id");
   while ($run_note = mysql_fetch_assoc($note_query)){
      $note_date = $run_note['Note_added_dat'];
      $formated_date=date("jS F Y H:i:s A",strtotime($note_date));
      echo $note_date;
      echo $formated_date;
     }

See other formats :http://php.net/manual/en/function.date.php

EDIT: As per comment

$date='2015-12-16 02:24:33';
$formated_date=date("jS M Y H:i:s A",strtotime($date));
echo $formated_date;
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
1

Use MySQL Date_Format function:

select date_format(date_column,'%D %M %Y %r')

SQL Fiddle Example: http://sqlfiddle.com/#!9/9eecb7d/35713

For more information for date formats : http://www.w3schools.com/sql/func_date_format.asp

Abhishek Ginani
  • 4,511
  • 4
  • 23
  • 35
1

See this SO post for your question. Convert from MySQL datetime to another format with PHP.

Also, please check out the PHP Documentation (I recommend reading all the way through it). You really should NOT be using the mysql extension as it is deprecated. Instead use myqli or PDO.

http://php.net/manual/en/book.mysqli.php

Community
  • 1
  • 1
1

using the date function of php

echo date('jS F Y H:i:s A',strtotime('2015-12-16 02:24:33'));
roullie
  • 2,830
  • 16
  • 26