Re: reformatting date string
| From: | David Knape | Date: | Tue, 29 Aug 2000 16:33:01 +0000 |
| Subject: | Re: reformatting date string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14170@lists.php.net to get a copy of this message | ||
I just happend to write something similar yesterday to convert mysql date
stamps. In that case, just explode at the hyphens. Here, we just convert
the number to a string, then use string functions. It only looks long,
because of the case statements that set the month.
---begin php---
$date = strval(20000826);
$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
switch($month){
case "01": $month = "January";
break;
case "02": $month= "February";
break;
case "03": $month = "March";
break;
case "04": $month = "April";
break;
case "05": $month = "May";
break;
case "06": $month = "June";
break;
case "07": $month = "July";
break;
case "08": $month = "August";
break;
case "09": $month = "September";
break;
case "10": $month = "October";
break;
case "11": $month = "November";
break;
case "12": $month = "December";
break;
}
echo "$month $day, $year";
---end php---
-David
David Knape
Web Application / Multimedia Developer
dave@tkdave.com
----- Original Message -----
From: "dbarber" <dbarber@sailnet.com>
Newsgroups: php3.general
Sent: Tuesday, August 29, 2000 10:03 AM
Subject: [PHP] reformatting date string
> Hi,
>
> I'm trying to do something which should be very simple, but I can't seem
> to make it work with any of the date functions or regular
> expressions.
>
> I'm trying to take a timestamp from in the format of '20000826' and
> change it to 'Aug 26, 2000'. The timestamps change with every entry.
>
> If anyone can help, I'd appreciate it.
>
> thanks,
>
> Dan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>