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
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have a date: 2015-06-24
I want to display it as 24 June
I have written this code.
$evnt_start_date = date('F m', strtotime($evnt_details['events_date']));
It displays the result like: June 06
What am I doing wrong?
m is number of month. Use d in reverse order:
$evnt_start_date = date('d F', strtotime($evnt_details['events_date']));
read more about date()
<?php
echo date('d F', strtotime($evnt_details['events_date']));
?>
This will output in this format DD-MM
date() Formatting Methods...
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$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'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$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 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>
Below code will give you 24 June.
date("d F",strtotime($evnt_details['events_date']));
Many of the answers above will work just fine for you, but I'd like to suggest a really awesome way to work with Dates and Time in PHP. It's DateTime and their related classes; to answer your question:
$dateString = '2015-06-24';
$date = new \DateTime($dateString);
$evnt_start_date = $date->format('d F');
See the following links:
http://php.net/manual/en/class.datetime.php - DateTime
Some extra reading that will help both now and in the future:
http://www.phptherightway.com/#date_and_time - PHP the right way
Use j for not leading 0 and use d for leading zero.
Not leading Zero:
$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('j F', strtotime($evnt_details['events_date']));//24 June
Leading Zero:
$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('d F', strtotime($evnt_details['events_date']));//24 June
I have this date in my database 11/06/2013 12:00
This is my code and the format I would like it in
$dateformatstart = date_format(date_create($row['datestart']), 'D j M y H:i');
Although it comes back as
Wed 6 Nov 13 12:00
Think the month is the day and day is the month, I don't know why
Thanks
Maybe this helps:
$date = DateTime::createFromFormat('d/m/Y H:i', $row['datestart']);
$dateformatstart = date_format($date, 'D j M y H:i');
Have you even checked out the php manual before asking this question?
Well, Here are some clever ways on how to format dates in PHP
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$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'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$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 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
$today = date("Y/m/d H:i"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
If you are trying to output a data format like this :
11/06/2013 12:00
then better, Use
$today = date("d/m/Y H:i");
I have created a script through which i retrieve values from a rss feed.
One value is in following date format:
Thu, 14 Apr 2011 18:23:19 GMT
What i wanted this value to be in following format:
April 14, 2011 11:53 PM
How can i achieve this?
Please help me on this
Thanks
Pankaj
The DateTime class is handy for this. You can use its format() method.
$datetime = new DateTime('Thu, 14 Apr 2011 18:23:19 GMT');
echo $datetime->format('F j,Y g:i A');
$olddate = "Thu, 14 Apr 2011 18:23:19 GMT";
$newdate = date("F d, Y H:i A",strtotime($oldDate));
Try it:
echo (date('F j,Y g:i:A',strtotime($Yourinputdate)));
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$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'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$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 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
above code taken from : http://www.php.net/manual/en/function.date.php
i didnot see you have an input so here it is:
$date = new DateTime('Thu, 14 Apr 2011 18:23:19 GMT');
echo $date->format("F j, Y g:i a");
Try this and see if it helps
echo(date('F j,Y g:i:A',strtotime(Date_From_RSS)));
This question goes along with another one of my post that I already accepted
How do I get the "date number" in php
2010-08-24 20:00:00.000
I want to assign the current date number to a variable $current_date_num so I can use it in my query to compare what is already in the database.
$query ="SELECT * FROM Reservations WHERE [Room_ID] = '$field' AND [Meeting Start] > '$current_date_num' ORDER BY [Meeting Start] asc ";
If you are only using it in the database, consider NOW
To get the current date number in the format above you would do:
echo date("Y-m-d H:i:s.u")
well, you can get the date number like this.. ex. from php.net http://php.net/manual/en/function.date.php.
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$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'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$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 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
$current_date_num = date("Y-m-d H:i:s.u", time());
refer to http://php.net/manual/en/function.date.php
If you are trying to specify it in the page from user side
use it this way
strtotime($time1)
how to I convert a unix timestamp 1280214000 to human readable date?
you can also use the date function
http://us.php.net/manual/en/function.date.php
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$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'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$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 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
Just pass in your unix timestamp as the second parameter.
You can use strftime. E.g.:
strftime("%x", 1280214000);
See the documentation for all the formatting options.
You can use date:
date('Y-m-d H:i:s', $timestamp);
//Monday 8th of August 2005 03:12:46 PM
echo(date("l jS \of F Y h:i:s A", "1280214000"));
You can use the date function.
http://php.net/manual/en/function.date.php