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");
Related
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);
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I' am trying to convert 16/06/2014 8:00 am to 16th June, 2014 8:00 AM
This is the format of the original date.
$date_time = '16/06/2014 8:00 am';
What does that above give me
01st January 1970 12:01 AM
This is the code in place
$date_time = date("dS F Y h:m A", strtotime($date_time ));
You can use DateTime::createFromFormat():
$date_time = '16/06/2014 8:00 am';
$date = DateTime::createFromFormat('d/m/Y g:ia', $date_time);
echo $date->format('dS F Y h:m A');
Note: you are using m here, which is a month representation. You should use i instead for the number of minutes:
dS F Y H:i A
You just need to change / slashes with - minus
$date_time = '16/06/2014 8:00 am';
$date_time = str_replace('/', '-', $date_time);
$date_time = date("dS F Y h:i A", strtotime($date_time ));
//here change m with i for minutes, m is for months
echo $date_time;
//output 16th June 2014 08:00 AM
Working sample here
This is weird, i'm trying to echo out a date like Monday, January 1, 2013, but its echoing out the wrong textual day. I don't have a clue why?
I have:
<?php echo date('l, F n, Y', strtotime($do['dueDate'])); ?>
And $do['dueDate'] is the date from the database of "2013-03-22". Its formatted as DATE in mysql.
When the above echos out it says: Friday, March 3, 2013
But march 3, 2013 is a sunday...
Try like this
echo date('l ,F j ,Y', strtotime($do['dueDate']));
Try this :
n --> Numeric representation of a month, without leading zeros --> 1 through 12
j --> Day of the month without leading zeros --> 1 to 31
<?php
$do['dueDate'] = "2013-03-22";
echo date('l, F j, Y', strtotime($do['dueDate']));
?>
Output :
Friday, March 22, 2013
use this
<?php
echo date('l, F j, Y', strtotime("2013-03-22")); // output Friday, March 22, 2013
working example http://codepad.viper-7.com/rF6w1U
http://php.net/manual/en/function.date.php
n is the numerical representation of the month.
try this:
$date = "2013-03-22";
echo date('l, F j, Y', strtotime($date));
outputs:
Friday, March 22, 2013
Is there anyway to convert the value of idate("z") to a date format that reads the Day, Month, and Year? My code looks like this:
$date_int = idate("z");
$date_text = strtotime($date_int);
$date = date("l, F j, Y", $date_text);
For some reason, it's still echoing Thursday, January 1, 1970.
Any ideas?
idate("z") is incorrect as that will return the day of the year. It seems like you want idate("U"), but in that case just use date() without the second parameter, it will assume time(). Example:
$date = date("l, F j, Y");
That should be all you need.
idate("z") will only return the day of the year. Today being 74. strtotime will not understand 74 as a parsing format. Therefore date() fails all together.
Assuming you want the date of the CURRENT YEAR:
$dayOfYear = 80;
print date("l, F j, Y", strtotime($dayOfYear - idate("z") . " day")); // Wednesday, March 21, 2012
$dayOfYear = 1;
print date("l, F j, Y", strtotime($dayOfYear - idate("z") . " day")) // Monday, January 2, 2012
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