i just need date format like this "26 March 2015 - 11:59 pm"
how to get 'pm'in my code
$month_year=date('F Y');
$timestamp = strtotime("$month_year");
$result = date('t F Y - 11:59 a', $timestamp);
Try below code
$date = date("d F Y - h:m a");
Just use DateTime like this:
$date = DateTime::createFromFormat("h:i a", "11:59 pm");
echo $date->format("d F Y - h:i a");
Output:
09 March 2015 - 11:59 pm
Check this
$month_year=date('F Y');
$timestamp = strtotime("$month_year");
echo $result = date('t F Y - H:i a', $timestamp);
Related
I am saving date and time in a single column i.e 2015-04-15 13:22:58 and I want to show this time and date in this format: 15th April 2015, 1:22 pm.
I have used this code:
$dt = '2015-04-15 13:22:58';
echo date("jS F Y", strtotime($dt));
and it shows only date (15th April 2015). How can I fetch time along with date?? Any help would be highly appreciable.
Try
$dt = '2015-04-15 13:22:58';
echo date("jS F Y h:i a", strtotime($dt));
//Result is 15th April 2015 01:22 pm
echo date("jS F Y g:i a", strtotime($dt));
// Result is 15th April 2015 1:22 pm
change "jS F Y" to "js F Y g:i a". That will output the time in your desired format as well as the date.
$dt = '2015-04-15 13:22:58';
echo date("jS F Y g:i a", strtotime($dt));
Output:
15th April 2015 1:22 pm
if you want to format date time in php, you can use date_format like this.
echo date_format(strtotime($dt), "jS F Y g:i A");
My date is "04 February 2017 - 06:35"
How can I Change into Date Object ?
I tried
$date = date_create_from_format('d/M/Y:H:i:s', "04 February 2017 - 06:35");
But its not Working
Time and the format should be corresponding! Your format is d M Y - H:i.
<?php
$date = DateTime::createFromFormat('d M Y - H:i', "04 February 2017 - 06:35");
echo $date->format('Y-m-d H:i:s');
Try This
You cannot get direct object of string you have to use date_format
$date = date_create_from_format('j M Y - H:i', "04 February 2017 - 06:35");
echo date_format($date,"Y-m-d H:i:s");
In php I have time like this
$time = '2015-06-29T16:00:00Z';
I want to convert that time like this format Tuesday, December 16, 2015 3:00 PM
For that I tried
echo date( 'jS F Y', strtotime( $time) );
but it is showing time like 1st January 1970
So can someone help me to get the actual time format as I want.
A simple DateTime class usage should suffice, just feed it into the constructor, the just use ->format and provide the desired output format:
$time = '2015-06-29T16:00:00Z';
$date = new DateTime($time);
echo $date->format('jS F Y');
Sample Output
You can use the DateTime class for better handling of dates
$time = '2015-06-29T16:00:00Z';
$dateTime = new DateTime($time);
echo $dateTime->format('l, F d, Y g:i A');
$time = '2015-06-29T16:00:00Z';
echo date( 'l, F j, Y H:i A',strtotime($time));
l, F j, Y H:i A can be re-ordered to change the output.
About date function, http://php.net/manual/en/function.date.php
Just pass proper format parameters to it.
$time = '2015-06-29T16:00:00Z';
echo date( 'l, F j, Y g:i A', strtotime( $time) );
Use preg_split:
$parts = preg_plit("/Z/",$time);
$parts = preg_split("/T/",$parts[0]);
$theDate=$parts[0];
$theTime=$parts[1];
$what_you_want=date(strtotime($theDate." ".$theTime);
Note that you can still change the format of the output.
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
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Format mysql datetime with php
I take and store a date into a mysql database. It displays like this:
2011-03-17 17:49:49
But I want it to show like this instead:
Thur 17 March 2011 5:49 PM
use date() in PHP: http://us.php.net/manual/en/function.date.php
or
format your output in mysql: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Convert it into a timestamp with strtotime(), and then format it with date() in PHP.
You should do formatting with date function.
date('D d F Y g:i a', strtotime($date));
Refer to manual for more.
Use the below function
date("D j F, Y, g:i a");
$today = date(”F j, Y, g:i a”); -> February 5, 2010, 6:20 pm
refer these links it may help u link1 link2 link3
$time = '2011-03-17 17:49:49';
$date = new DateTime($time);
echo $date->format('D j F Y g:i A'); // Thu 17 March 2011 5:49 PM
Note that in your example, you have Thur and not Thu as per my output. PHP doesn't have any native character to represent this, but you could do...
$time = '2011-03-17 17:49:49';
$date = new DateTime($time);
echo substr($date->format('l'), 0, 4) . $date->format(' j F Y g:i A');
// Thur 17 March 2011 5:49 PM
best to store dates in the db as unix time stamp then when there outputted use something like this to display it how you want
<?php
// echo date ( "F j, Y, g:i a", timestamp );
// Assuming today is: March 10th, 2001, 5:16:18 pm
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
$today = date("H:i:s"); // 17:16:17
?>
$given_date = '2011-03-17 17:49:49';
echo $ur_date = date('D j F Y g:i:s A',strtotime($given_date));
http://www.php.net/manual/en/datetime.createfromformat.php