[GLLUG] MySQL Help

Brad Fears brad at tricountywebdesign.com
Thu Mar 30 22:16:23 EST 2006


DISCLAIMER: Untested, quick, and dirty, but this should do it.  Good luck.

$query = "SELECT index,birthday FROM your_table";
$result = mysql_db_query($dbname, $query);
while ($r = mysql_fetch_array($result)) {
	$index = $r["index"];
	$birthday = $r["birthday"];
	$bd_parts_array = explode("-", $birthday);
	if (strlen($bd_parts_array[0]) == 4) {
		$new_order =
$bd_parts_array[1]."-".$bd_parts_array[2]."-".$bd_parts_array[0];
	}

	$update = "UPDATE your_table SET birthday='".$new_order."' WHERE
index='".$index."'";
	unset($index,$birthday,$bd_parts_array,$new_order);
}


Brad Fears
Tri-County Web Design, LLC
http://www.tricountywebdesign.com
(517) 712-6668


> I've got a problem with a MySQL database and need some help.
>
>
>
> The field 'birthday' is varchar and a recent import of users placed
> birthdates in the following format.
>
> 1970-12-31
>
>
>
> There are supposed to be
>
> 12-31-1970
>
>
>
> I need to be able to fix this, but not change the ones that are correct.
>
>
>
> I could so this in switch easily in ColdFusion and MSSQL (my home turf),
> but I'm not sure about PHP and MySQL.
>
>
>
> Can anyone help me with a quick fix for this?
>
>
>
> Mel Wade, IT Director
>
> Michigan Conference of Seventh-day Adventists
>
> 517.316.1580
>
> 517.316.1582 Fax
>
> "Change is Inevitable. Growth is Optional."
>
>
>
> _______________________________________________
> linux-user mailing list
> linux-user at egr.msu.edu
> http://mailman.egr.msu.edu/mailman/listinfo/linux-user
>






More information about the linux-user mailing list