Here's the stuff I've written to do this.
Syntax:
mysqldate_format($timestamp, $format)
where $timestamp is a 14-digit mySQL timestamp and $format can contain these characters:
YYYY - four digit year
yy - two digit year
MM - two digit month
SM - one digit month
DD - two digit date
SD - one digit date
hh - hours
mm - minutes
ss - seconds
MONTH - full month name
MN - abbr. month name
DAY - full day name
DN - abbr. day name
So to get "23. August 2003 06:12pm" you'd write:
mysqldate_format($timestamp, "DD. MONTH YYYY hh:mmpm");
You'll need both the functions below to use the one.
function mysqldate_format($datum, $format) {
$monthname = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$monthnamelong = array("January","February","March","April","May","June","July","August","September","October","November","December");
$dayname = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
$daynamelong = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$unixdate = mysql_to_epoch($datum);
$year = substr($datum, 0, 4);
$smallyear = substr($datum, 2, 2);
$month = substr($datum, 4, 2);
$day = substr($datum, 6, 2);
$hour = substr($datum, 8, 2);
$minutes = substr($datum, 10, 2);
$seconds = substr($datum, 12, 2);
$weekday = date("w", $unixdate);
if ($day < 10) {
$shortday = substr($day, 1, 1);
}
else {
$shortday = $day;
}
if ($month < 10) {
$shortmonth = substr($month, 1, 1);
}
else {
$shortmonth = $month;
}
$format = ereg_replace("YYYY", $year, $format);
$format = ereg_replace("yy", $smallyear, $format);
$format = ereg_replace("MM", $month, $format);
$format = ereg_replace("SM", $shortmonth, $format);
$format = ereg_replace("DD", $day, $format);
$format = ereg_replace("SD", $shortday, $format);
$format = ereg_replace("hh", $hour, $format);
$format = ereg_replace("mm", $minutes, $format);
$format = ereg_replace("ss", $seconds, $format);
$format = ereg_replace("MN", $monthname[$month-1], $format);
$format = ereg_replace("MONTH", $monthname_long[$month-1], $format);
$format = ereg_replace("DAY", $daynamelong[$weekday-1], $format);
$format = ereg_replace("DN", $dayname[$weekday-1], $format);
return $format;
}
function mysql_to_epoch ($date) {
$year = substr($date, 0, 4);
$month = substr($date, 4, 2);
$day = substr($date, 6, 2);
$hour = substr($date, 8, 2);
$minute = substr($date, 10, 2);
$second = substr($date, 12, 2);
return date("U",mktime($hour,$minute,$second,$month,$day,$year));
}