View Full Version : Format date from a string

04-10-2003, 02:10 PM
Say I have a date in a string, "10 04 2003". Is there a function to convert the date into another format? I had a look through the documentation but didn't find it..

I imagine that PHP would have one, I mean even ASP can do it.;)

04-10-2003, 02:17 PM
use this functions:
(PHP 3>= 3.0.12, PHP 4 >= 4.0.0)

strtotime -- Parse about any English textual datetime description into a UNIX timestamp
(PHP 3, PHP 4 >= 4.0.0)

date -- Format a local time/date
string date ( string format [, int timestamp])
Returns a string formatted according to the given format string using the given integer timestamp or the current local time if no timestamp is given.

04-10-2003, 02:25 PM
Ok I think I get what you told me, plus I looked it up in the manual but I'm still getting an error on the line where I use date()..

$timestamp = mysql_result($result,$i,"makedate") or die("Unable to extract date!");
$timestamp = strtotime($timestamp);
$makedate = date("d M y", $timestamp);

TIA! :D:)

[edit:]Warning: unexpected error in date() in c:\phpdev\www\news_cast.php on line 24

04-10-2003, 02:30 PM
Naturally. :)

$makedate_=_date("d M y",_$timestamp));
Unmatched parenthesis

04-10-2003, 02:34 PM
Hehe, I noticed that before I edited but after fixing I get the error in red..

04-10-2003, 03:00 PM
1970-09-17 # ISO 8601.
70-9-17 # This century assumed by default.
70-09-17 # Leading zeros are ignored.
9/17/72 # Common U.S. writing.
24 September 1972
24 Sept 72 # September has a special abbreviation.
24 Sep 72 # Three-letter abbreviations always allowed.
Sep 24, 1972

$makedate=date("d M y",$timestamp);
echo $makedate;

It works for me

04-10-2003, 03:11 PM
Aahh Okies! I had 10 04 2003 .. spaces. :rolleyes: Thankyou weirdan! :thumbsup: