PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
seodevhead
Forum Regular
Posts: 705 Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL
Post
by seodevhead » Wed Apr 05, 2006 1:21 pm
Hey guys... I have a database that has dates stored in the following format:
2006-04-05
Is there anyway in PHP to convert this to April 5, 2006? Even better, knock off the year and just get April 5? Thanks for your help!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 05, 2006 1:31 pm
You could use the databases' own functionality such at MySQL's DATE_FORMAT function.
For PHP to handle it correctly,
explode() it then pass the data to
mktime() and finally that result through
date() in the format string you wish.
irisblaze
Forum Newbie
Posts: 22 Joined: Sun Mar 19, 2006 3:24 am
Location: Palestine
Contact:
Post
by irisblaze » Wed Apr 05, 2006 2:15 pm
Code: Select all
<?php
$timestamp = strtotime("2006-04-05");
//print date as April 05, 2006
echo date("F d, Y", $timestamp);
echo "<br/>";
//print date as April 05
echo date("F d", $timestamp);
?>
Now it should work
Last edited by
irisblaze on Wed Apr 05, 2006 2:18 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 05, 2006 2:17 pm
unfortunately, strtotime() may read the date wrong, depending on locale and other things, so be very careful using it in this case.
irisblaze
Forum Newbie
Posts: 22 Joined: Sun Mar 19, 2006 3:24 am
Location: Palestine
Contact:
Post
by irisblaze » Wed Apr 05, 2006 2:25 pm
feyd wrote: unfortunately, strtotime() may read the date wrong, depending on locale and other things, so be very careful using it in this case.
not if you pass the date in the right format!
I mean let's say that you passed the string as 2006-12-20, does strtotime returns time stamp for the date 2006-20-12 depending on the locale?