[geeklog-devel] Feature Request: Add $uid to COM_getUserDateTimeFormat

Joe Mucchiello joe at ThrowingDice.com
Sun Aug 19 13:32:12 EDT 2007

Sometimes you need to user date format for a user who is not the current user.

I've also cleaned up the code, removed typos from the comment and 
included 1.4.1 and CVS compatible versions.

* Returns formatted date/time for user
* This function takes a date in either unixtimestamp or in english and
* formats it to the users preference.  If the user didn't specify a format
* the format in the config file is used.  This returns an array where array[0]
* is the formatted date and array[1] is the unixtimestamp
* @param    string      $date       date to format, otherwise we 
format current date/time
* @param    numeric     $uid        Which user id to get the format 
for. If empty, current user is used.
* @return   array   array[0] is the formatted date and array[1] is 
the unixtimestamp.
function COM_getUserDateTimeFormat($date='', $uid = 0)
     global $_TABLES, $_USER, $_CONF;

     // Get display format for time

     if (!empty($uid) AND $uid > 1) {
         $dateformat = DB_getItem($_TABLES['users'], 'format', "uid = $uid");
     } else if (!COM_isAnonUser() AND !empty($_USER['format'])) 
{    // the CVS version
//    } else if (!empty($_USER['uid']) AND $_USER['uid'] > 1 AND 
!empty($_USER['format'])) {     // the 1.4.1 version
         $dateformat = $_USER['format'];
     } else {
         $dateformat = $_CONF['date'];

     if (empty($date)) {
         $stamp = time();            // Date is empty, get current date/time
     } else if (is_numeric($date)) {
         $stamp = $date;             // This is a timestamp
     } else {
         $stamp = strtotime($date);  // This is a string 
representation of a date/time

     // Format the date
     $date = strftime($dateformat, $stamp);

     return array($date, $stamp);

Joe Mucchiello
Throwing Dice Games

More information about the geeklog-devel mailing list