Reputation: 1047
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;
}
Upvotes: 0
Views: 42
Reputation: 38502
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;
Upvotes: 3
Reputation: 2820
using the date function of php
echo date('jS F Y H:i:s A',strtotime('2015-12-16 02:24:33'));
Upvotes: 1
Reputation: 13
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
Upvotes: 1
Reputation: 4751
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
Upvotes: 1