NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help converting MySQL datetime to month

Jon Baer jonbaer at jonbaer.com
Thu Oct 19 23:57:58 EDT 2006


You can also now do it directly in MySQL ... might be available as  
UDF on older versions.

mysql> select monthname('2006-10-19') as month;
+---------+
| month   |
+---------+
| October |
+---------+
1 row in set (0.00 sec)

- Jon

On Oct 19, 2006, at 9:28 PM, Randal Rust wrote:

> I have a function that does what I want, I just find it hard to
> believe that there isn't something better. So any pointers would be
> greatly appreciated.
>
> function convertDatetime($value){
> 	$value=explode(" ", $value);
> 	$value=explode("-", $value[0]);
> 	$y=$value[0];
> 	$m=$value[1];
> 	$d=$value[2];
> 	switch($m){
> 		case '01':
> 			$m='January';
> 			break;
> 		case '02':
> 			$m='February';
> 			break;
> 		case '03':
> 			$m='March';
> 			break;
> 		case '04':
> 			$m='April';
> 			break;
> 		case '05':
> 			$m='May';
> 			break;
> 		case '06':
> 			$m='June';
> 			break;
> 		case '07':
> 			$m='July';
> 			break;
> 		case '08':
> 			$m='August';
> 			break;
> 		case '09':
> 			$m='September';
> 			break;
> 		case '10':
> 			$m='October';
> 			break;
> 		case '11':
> 			$m='November';
> 			break;
> 		case '12':
> 			$m='December';
> 			break;
> 		}
> 	$dt=$m.' '.$d.', '.$y;
> 	$value=$dt;
> 	return $value;
> 	}
>
> -- 
> Randal Rust
> R.Squared Communications
> www.r2communications.com
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php




More information about the talk mailing list