View Full Version : formatting time outside of vb based on offset
I want to make a new page which shows news, .. however I would like to format the time from my queries based on the offset the users put in their profile.
take this code for example:
<?
$bbuserinfo[tzoffset]=-7;
$result = mysql_query("select title,body,unix_timestamp(time) as time from news order by time desc");
?>
how do i incorporate the tzoffset into my query to reflect the local time for the user viewing the news?
my time field is stored as a datetime type, .. i can change it to integer14 and store the unix timestamp if that is necessary.
thanks
Boofo
05-24-2004, 04:31 AM
Here's what I did for my users online today part of forumhome and it seems to work great for each user's time offset.
$timestamp = vbmktime(0, 0, 0, vbdate('m', TIMENOW, false, false), vbdate('d', TIMENOW, false, false), vbdate('Y', TIMENOW, false, false));
Then set up your query something like this:
<?
$result = mysql_query("select title,body from news WHERE dateline >= $timestamp order by dateline desc");
?>
The $timestamp will get each user's time according to their offset.
thanks a lot boofoo =) your help is much appreciated!
err wait, .. that does help me figure out how to display the user's current time .. and query against that, .. but when i display my news, it will always display the same news articles. there will be no 'where' clause.
when i loop through the news, i need to display the time as the user's current time.
.. heh and as i think about it, would i do something like this?
<?
$result = mysql_query("select title,body,unix_timestamp(time) as time from news order by time desc limit 10");
while($row = mysql_fetch_array($result)){
// does this next line convert the news article time to the user's timezone?
$timestamp = vbmktime(0, 0, 0, vbdate('m', $row[time], false, false), vbdate('d', $row[time], false, false), vbdate('Y', $row[time], false, false));
}
?>
thanks
=/ now that i tried it, i can't figure out where vbmktime() is located.
i'm including global.php, do i need to include something else for that function?
Boofo
05-24-2004, 05:43 AM
I'm sorry, I forgot to add this:
require_once('./includes/functions_misc.php');
;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.