>Sent: Monday, August 26, 2002 3:58 PM
>Subject: [PHP] Date conversion problems

> Having a little trouble with converting dates.
> I have, in my database, a bunch of dates stored like this: YYYY-M. Month
> 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
> 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,
> 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
> ears.

mktime generally only works thru 2037.  Why not create an array of the
months, and index in:
$months = array('Jan','Feb',....);
$enddate = explode("-", $datereuslt[0]);
$finaldate =  $months[$enddate-1] . "-$enddate[1]";

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to