2011-07-13 02:38:31
^ MySQL format.
I would like to use PHP to convert it to another format like , July 13, 2011 2:38 am.
<?php
$time_from_db = '2011-07-13 02:38:31';
echo date('F j, Y g:i a', strtotime($time_from_db));
?>
echo date("F j, Y g:i a", strtotime("2011-07-13 02:38:31"));
demo
$yourdatevar = date("F j, Y, g:i a", strtotime($yourdatevar)); // March 10, 2001, 5:16 pm
Taken right from: http://php.net/manual/en/function.date.php
Related
How to add GMT +530 to "M j, Y, g:i a" format using php. I am trying to add the GMT +530 Like
M j, Y, g:i a +530
But not able to get the desired result.
Try this
<?php
$date = date("M j, Y, g:i a", strtotime('+5 hours +30 minutes'));
echo $date;
?>
I want to display date and time format something like this "May 23 at 12:30pm".
I saw in PHP manual and found:
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');
After modification I manage to get
echo date('M j \of h:i a');
it is giving me "May 23 of 12:30pm"
but when i replacing of with at it is giving me "May 23 a23 08:26 pm".
I don't what is going wrong.
you need to escape the a and t as both have special meaning when used as formatting options in date()
echo date('M j \a\t h:i a');
See it in action
Try
<?php
echo date('M j \a\t h:i a');
?>
OR
<?php
echo date('M j'). "at". date(' h:i a');
?>
You need to escape the t too:
echo date('M j \a\t h:i a');
Another option could be:
echo date('M j')." at ".date('h:i a');
You need to try this in php:
$t = now(); //This will give you current time
echo date_format($t,"dS M,y \a\\t h:i a"); //14th May,19 at 05:39am
i tried using date("F j, Y \a\t h:i a", strtotime($date));
but this produces May 20, 2013 a 04:37 pm
i also tried date("F j, Y \at\ h:i a", strtotime($date)); and
date("F j, Y \a\t\ h:i a", strtotime($date));
and it became May 20, 2013 a31 04:37 pm
what i want to produce is this May 20, 2013 at 04:37 pm
Thanks!
With double quotes \t will be interpreted as a tab character. Using single quotes (or double slashes) takes care of the issue:
echo date('F j, Y \a\t h:i a', strtotime('2013-05-20 23:59:59'));
// output: May 20, 2013 at 11:59 pm
i have a string that is like this 2012/10/12 10:03:46 (Year/Month/Day) format now i want to change its format to something like this October 12, 2012 10:03 p.m i have tried php's DateTime class but its not working:
<?php
$date = new DateTime();
$date->createFromFormat('Y/m/dd H:i:s', substr($suggestion->suggestion->created_at, 0,19));
echo $date->format('d-m, y h:i A');
?>
can anyone tell me whats wrong and how can i correct it??
You should have seen at least one notice something like "don't call static function in non-static context".
DateTime::createFomFormat()
$date = DateTime::createFromFormat('Y/m/d H:i:s', substr($suggestion->suggestion->created_at, 0,19));
echo $date->format('F j, Y, g:i a');
It's a static method and (as the name suggests) it creates a new instance of DateTime.
$today = date("F j, Y, g:i a");
<?php
$date = new DateTime('2012/10/12 10:03:46');
echo $date->format('d-M, y h:i:s A');
//output - 12-Oct, 12 10:03:46 AM
?>
Try this...
$today = date("F j, Y h:i a"); // gives October 15, 2012 5:20 PM
Try this...
$today = date("F j, Y g:i A"); // gives October 15, 2012 5:20 PM (g removes leading zeroes)
Your case
$date = new DateTime('2012/10/12 10:03:46');
echo $date->format('F j, Y h:i A'); // gives October 15, 2012 10:03 AM
Reference : click
I have the following timestamp:
1341111034380
Which equates to:
Sun, 01 Jul 2012 02:50:34 GMT
However, when I try to format this using:
date("F j, Y, g:i a", 1341111034380)
I get:
February 12, 44468, 5:53 am
Any ideas why it would do this?
You have the wrong units.
1341111034380 is in milliseconds, whereas a proper timestamp is in seconds, which is what PHP expects.
If you want to use it in PHP, you should convert it to seconds.
echo date("F j, Y, g:i a", floor(1341111034380/1000));
use:
echo date("F j, Y, g:i a", substr(1341111034380, 0, 10));