A common problem you may find when adding dates to mySQL is that mySQL date column have differing formats to what we humans like to read. This easy function makes the dates interchangable.

//sets $date as current date in familiar format.

$date = date('d-m-Y');

//swaps year and day around for insertion to database

$date = changeDate($date);

//The function goes anywhere on your page

function changeDate($date) {

// explode $date into an array seperated by the colon
$tempDate = explode('-',$date);
//change year and day around (eg 29-04-2010 will become 2010-04-29)
$date = $tempDate[2].'-'.$tempDate[1].'-'.$tempDate[0];

return $date;

}

?>

Leave a Reply

You must be logged in to post a comment.