...

View Full Version : Format date from a string



Mhtml
04-10-2003, 01: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.;)

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

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

date -- Format a local time/date
Description
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.

Mhtml
04-10-2003, 01: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

Weirdan
04-10-2003, 01:30 PM
Naturally. :)

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

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

Weirdan
04-10-2003, 02: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
24-sep-72
24sep72



$timestamp="10/04/03";
$timestamp=strtotime($timestamp);
$makedate=date("d M y",$timestamp);
echo $makedate;


It works for me

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum