Re: Format date

From: Date: Sat, 13 Oct 2001 15:18:16 +0000
Subject: Re: Format date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-70988@lists.php.net to get a copy of this message
> I have about 5 million records in a varchar field in mysql that look > like 10-Jan-2001 I need to get them formated to appear as 2001-01-10 > anyone have any ideas how I can go about this. This is assuming that the date field you wish to reformat is called dateField, you have a unique key called id, and the table is called tableName: $sth = mysql_query("SELECT id, dateField FROM tableName"); while( $res = mysql_fetch_array( $sth ) ) { $newDateField = substr( $res[dateField], 6, 4 ) . '-' . substr( $res[dateField], 0, 2 ) . '-' . substr( $res[dateField], 3, 2 ); mysql_query("UPDATE tableName SET dateField = '$newDateField' WHERE id = $res[id]"); } mysql_free_result( $sth );

« previous php.general (#70988) next »