Helpful wrapper function used in my Form Tools script for converting a MySQL datetime into a human readable format. Includes the option of specifying hour offset. It gets pretty annoying having to rethink this problem every time you need it, so here it is for reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*-----------------------------------------------------------------------------------------*\
  Function:    get_date
  Description: helper function to return a date according based on an offset and a display format.
  Parameters: $offset     - the GMT offset
                   $datetime - the mysql datetime to format
                   $format    - the format to use (PHP's date() function).
\*-----------------------------------------------------------------------------------------*/

function get_date($offset, $datetime, $format)
{
  $year = substr($datetime,0,4);
  $mon  = substr($datetime,5,2);
  $day  = substr($datetime,8,2);
  $hour = substr($datetime,11,2);
  $min  = substr($datetime,14,2);
  $sec  = substr($datetime,17,2);

  return date($format, mktime($hour + $offset, $min, $sec, $mon, $day, $year));
}