note 57088 added to function.gmdate

From: Date: Fri, 23 Sep 2005 08:16:33 +0000
Subject: note 57088 added to function.gmdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-95646@lists.php.net to get a copy of this message
Gives user the ability to use their timezone preferences. I had to create this script for a very large community. I first made any posts to the database that would display the date using just time(); Example: mysql_query("INSERT INTO table (datetime) VALUES ('".time()."')"); Also, for their timezone preference, I had the values as (example): (Eastern Timezone) -5 hours (Newfoundland) -3 hours -30 minutes This information would be saved in the users table. To display the date and time in their respective timezone preference: function datetime($datetime,$zone){ if(date('I')):$datetime+=60*60;endif; return gmdate('m-d-Y - h:i:sa',strtotime($zone,$datetime)); } $datetime would be the information pulled from the database from a post for news, forums, etcetera (remember, the inserted table data for the time was using time();) $zone would be the information pulled from the database from the users timezone preference. I also used cookies to store their timezone: $sth=mysql_query("SELECT datetime FROM table LIMIT 1"); $row=mysql_fetch_assoc($sth); echo datetime($row['datetime'],$_COOKIE['timezone']); Remember to set the 'm-d-Y - h:i:sa' to how you wish the time to display. Visit the manual about date(). ---- Manual Page -- http://www.php.net/manual/en/function.gmdate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57088 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57088&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57088&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95646) next »