mic2100
05-18-2006, 10:22 AM
I have been using mySQL dates and the fromat they seem to always output is YYYY-MM-DD (HH:MM:SS), i was having to change each date to display on the screen for the users and this was becoming a problem. So i have written this function for converting dates into the correct formats.
function datechangefromDB($value, $type);
{
//type 1 is for just a date
if($type == 1)
{
//this breaks up the date into seperate parts
array($date = explode("-", $value));
//this sets the date in to the correct format
// 0 = YEAR, 1 = MONTH, 2 = DAY
$outputdate = $date[2]."-".$date[1]."-".$date[0];
echo $outputdate;
}
//type 2 is for datetime
elseif($type == 2)
{
//this explodes the datetime into seperate parts
array($datetime = explode(" ", $value));
//this explodes the date into seperate parts
array($date = explode("-", $datetime[0]));
//sets the outputdate to the correct format
// date = (0 = YEAR, 1 = MONTH, 2 = DAY)
// datetime = (0 = date, 1 = TIME)
$outputdate = $date[2]."-".$date[1]."-".$date[0]." ".$datetime[1];
echo $outputdate;
}
}
This has made my life easier, i'm sure there is a better way of doing it but this will do 4 me.
function datechangefromDB($value, $type);
{
//type 1 is for just a date
if($type == 1)
{
//this breaks up the date into seperate parts
array($date = explode("-", $value));
//this sets the date in to the correct format
// 0 = YEAR, 1 = MONTH, 2 = DAY
$outputdate = $date[2]."-".$date[1]."-".$date[0];
echo $outputdate;
}
//type 2 is for datetime
elseif($type == 2)
{
//this explodes the datetime into seperate parts
array($datetime = explode(" ", $value));
//this explodes the date into seperate parts
array($date = explode("-", $datetime[0]));
//sets the outputdate to the correct format
// date = (0 = YEAR, 1 = MONTH, 2 = DAY)
// datetime = (0 = date, 1 = TIME)
$outputdate = $date[2]."-".$date[1]."-".$date[0]." ".$datetime[1];
echo $outputdate;
}
}
This has made my life easier, i'm sure there is a better way of doing it but this will do 4 me.