Re: Date conversion problems
| From: | David Robley | Date: | Tue, 27 Aug 2002 05:44:08 +0000 |
| Subject: | Re: Date conversion problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114218@lists.php.net to get a copy of this message | ||
In article <D64360C926B9F34F8B35F78D07B8E7A24DBC56@postman.dfait-
maeci.gc.ca>, Liam.Gibbs@dfait-maeci.gc.ca says...
> Having a little trouble with converting dates.
>
> I have, in my database, a bunch of dates stored like this: YYYY-M. Month is
> obviously the number of the month (5), not the name (May).
>
> I want to convert the format to MMM, YYYY (ex: May, 2002), so I used the
> mktime function. Basically I extract the date with a regular MySQL query,
> then explode the date, and my components look great. However, when I put the
> components into my mktime function, sometimes it'll work and sometimes it
> won't. It won't work if the date is too far off in the future (2085, etc.),
> but I'm not exactly sure what the cutoff is. If it's recent, say 2005, it
> works fine.
>
> My code is this (after grabbing the query results):
> $enddate = explode("-", $datereuslt[0]);
> $fullenddate = mktime(0, 0, 0, $enddate[1], 0, $enddate[0]);
> $finaldate = date("M, Y", $fullenddate);
>
> Any ideas? Alternatively, if anyone has an easier way of doing this, I'm all
> ears.
>
Hmm, as mktime returns a unix timestamp it'll be constrained by that;
currently the unix timestamp covers a range from 1 Jan 1970 to (mumble)
January 2038.
However, if your date is stored using one of the mysql date or time
formats, why not try using mysql's DATE_FORMAT to pretty it up as you
select from the db? IIRC some of the date column types have a range of
around 10,000 years, which should meet your needs.
--
David Robley
Temporary Kiwi!
Quod subigo farinam