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)));
Related
I'll try format datetime like this Thu Jun 15 2017 14:12:28 GMT 0700 (SE Asia Standard Time) to format like 2017-06-5 in PHP. I use date_create but have errorl like this
Warning: date_format() expects parameter 1 to be DateTimeInterface, string given
and this my PHP code
$aa = date_format($w22,"Y-m-d");
echo $aa;
content from $22 is Thu Jun 15 2017 14:12:28 GMT 0700 (SE Asia Standard Time)
how to format datetime like mine, please help me to solved my problem. Thanks
You need to remove GMT 0700 (SE Asia Standard Time)
$w22 = date_create("Thu Jun 15 2017 14:12:28")
$aa = date_format($w22,"Y-m-d");
echo $aa;
<?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)
?>
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 urgently need to know how I can make dates appear in Spanish instead of in English in reminder emails sent to users via a cron task. With the current (".$upcoming_date."), the date shown in the emails is like this: Saturday, 26 November, 2011 21:19, and I would need this to change into the corresponding Spanish version or into something like 26/11/2011 21:19.
You will maybe need this function to convert the time if it is store somewhere. Good luck.
http://php.net/manual/en/function.strtotime.php
http://php.net/manual/en/function.date.php
$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 6Satpm01
$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
You don't. You change the value of the $format argument you pass to strftime().
strftime(_($someformat), $sometime)
For spanish dates ,You can do:
echo strftime("%A %e de %B del %Y - %H:%M:%S", mktime (gmdate("H"), gmdate("i"), gmdate("s")-16200, gmdate("n"), gmdate("j"), gmdate("Y")));
Hope it helps
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
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