RE: [PHP4BETA] Silly question re formatting dates from a database...
| From: | Mike Robinson | Date: | Wed, 15 Mar 2000 00:38:01 +0000 |
| Subject: | RE: [PHP4BETA] Silly question re formatting dates from a database... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-12117@lists.php.net to get a copy of this message | ||
> > Ok, so this is a really dumb question. Are there any functions
> > to format a date from a database? I can't find anything obvious
> > in either the string functions or in the date/time functions.
>
> Assuming mysql, you're probably storing dates in the native
> format; date (0000-00-00) or datetime (0000-00-00 00:00:00).
>
> If you want to change a datetime type date to something more
> friendly, this might work:
Sorry. That one got away from me...
Untested, under the influence:
$date = 2000-03-14 12:00:00;
$datearr = Array();
$datefields =
Array('year','mon','mday','hour','min','sec');
$datetimevals = split("[^[:digit:]]+",$date,6);
while ((list($idx,$field)=each($datefields)) &&
($idx<count($datetimevals))) {
$datearr[$field]=intval($vals[$idx]);
}
$datestring = ereg_replace(" 0"," ",strftime("%I:%M%p, %A, %B %d,
%Y",mktime($datearr['hour'],$datearr['min'],$datearr['sec'],$datearr['mon'],
$datearr['mday'],$datearr['year'])));
echo $datestring;
...should produce "12:00pm, Tuesday, March 14, 2000"
Time for some sleep I guess.
/mike