Mailinglisten-Archive |
On Wed, 31 Mar 1999 14:03:19 +0200, Christoph Hanser wrote:
>Hallo,
>ich lese aus der Mysql-Datenbank das datum im format 1999-03-31 aus. Es soll
>aber in 31.03.1999 erscheinen. Wie mach ich das?
>Andersherum: Jemand soll 31.03.1999 eingeben, das datum soll aber als
>1999-03-31 in MySQL eingelesen werden. Wie mach ich das?
Hier sind zwei funktionen, die das machen.
ciao
amalesh
/******************************************************************************
Function : FncFormatDateTime
Arguments : $strTimeStamp, $strFormat
Description: Übersetzt timestamp oder ISO in beliebiges anders Format
YYYY-MM-DD hh:mm:ss
Returns : $strFormat
*******************************************************************************/
function FncFormatDateTime ($strDatetime, $strFormat)
{
$strCheckTS = ereg_replace("-","",$strDatetime); // bilde checkvariable
if ($strDatetime == $strCheckTS) // Wenn format timestamp
{ $year = substr($strDatetime,0,4); // Ziehe das datum bei
Timestamp raus
$month = substr($strDatetime,4,2);
$day = substr($strDatetime,6,2);
$hour = substr($strDatetime,8,2);
$minute= substr($strDatetime,10,2);
$sec = substr($strDatetime,12,2);
}
else // Wenn format Date-time
{ $year = substr($strDatetime,0,4); // Ziehe das datum raus
$month = substr($strDatetime,5,2);
$day = substr($strDatetime,8,2);
$hour = substr($strDatetime,11,2);
$minute= substr($strDatetime,14,2);
$sec = substr($strDatetime,17,2);
}
// Analysiere Ausgabe-format
if (substr($strFormat,0,4) != "YYYY") /* Wenn nicht vier Y am anfang */
{ if (substr($strFormat,0,2) == "YY") /* Wenn zwei YY am anfang */
{ $strFormat = ereg_replace ("YY", substr($strDatetime,2,2),
$strFormat);
}
else /* wenn vier Y irgendwo */
{ $strFormat = ereg_replace ("YYYY", $year, $strFormat);
}
}
else
{ $strFormat = ereg_replace ("YYYY", $year, $strFormat);
}
$strFormat = ereg_replace ("MM", $month, $strFormat);
$strFormat = ereg_replace ("DD", $day, $strFormat);
$strFormat = ereg_replace ("hh", $hour, $strFormat);
$strFormat = ereg_replace ("mm", $minute, $strFormat);
$strFormat = ereg_replace ("ss", $sec, $strFormat);
return $strFormat;
};
/******************************************************************************
Function : FncGermanDate2ISO
Arguments : $strGermanDate (mm.dd.yyyy)
Description: Übersetzt deutsches Datum in ISO-Format
Returns : $strFormat
*******************************************************************************/
function FncGermanDate2ISO ($strGermanDate)
{
$year = substr($strGermanDate,6,4);
$month = substr($strGermanDate,3,2);
$day = substr($strGermanDate,0,2);
$strFormat = $year . "-" . $month . "-" . $day;
return $strFormat;
};
--
www : http://www.goatrance.de
email: amalesh_(at)_goatrance.de || aka_(at)_bigfoot.de || icq: 963380
Keep Agent alive: http://www.living-source.com/agent/
php::bar PHP Wiki - Listenarchive