Open Source Tutorials - Open Source Training
Open source training & tutorials from experienced, passionate people
chrome icon firefox icon ie icon opera icon safari icon Sings in these Browsers
A- A A+

By A Web Design

Welcome, Guest
Username Password: Remember me

Convert date to another format
(1 viewing) (1) Guest
All your queries regarding
PHP Installation,
Binding Apache-PHP-MySQL,
and tonnes more... will be solved in this forum
  • Page:
  • 1
TOPIC:

Convert date to another format

Convert date to another format 1 year, 4 months ago #444

  • dhuruv
  • OFFLINE
  • Senior Boarder
  • Posts: 60
  • Karma: 0
If i have to work with dates in the following format: "Tuesday, January 14, 2011 @ 10:39 am", how can we convert them to another format, that is easier to use?

Re: Convert date to another format 1 year, 4 months ago #481

  • kate
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Karma: 0
The strtotime function can convert a string to a timestamp.
A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

If
$date = "Tuesday, January 14, 2011 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);

Hope it helps you.
  • Page:
  • 1
Time to create page: 1.23 seconds
OSV Newsletter


Receive HTML?

NOTE: To prevent subscription to the OSV newsletter, uncheck the checkbox above.
Guest Blog for OSV
Free Ebook Download