Jump to content

Query with timezone adjustments


djones

Recommended Posts

I moved my host to another company and they are 13 hours ahead. I'm in the east coast of U.S. and the server host is in Perth, Australia. One of my SQL lines needs to be adjusted to allow for the timezone change. This is the current code thats needs to be set to 13 hours behind the now() functiion. Can anyone please help?

[code]
$sql .= "WHERE text IS NOT NULL AND (y*10000+m*100+d) >= ";
$sql .= "(YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) "; // This line needs to be adjusted to my time which is now 13 hours behind
[/code]
Link to comment
Share on other sites

Use INTERVAL

[code]$sql .= "( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13 HOUR )";[/code]

But I would look at using CONVERT_TZ() instead, surrounding each of your date functions...

If you don't want it to return datetime formart...

[code]2006-11-18 11:00:00[/code]

Then surround the above with with ( expression + 0 )

[code]$sql .= "( ( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13 HOUR ) + 0 )";[/code]

which will return....

[code]20061118110000[/code]


printf
Link to comment
Share on other sites

I'm not getting any results. Here is the full query:

$sql = "SELECT id, y, m, d, title, text, start_time, end_time, TIME_FORMAT( start_time, '%l:%i%p' ) AS stime, TIME_FORMAT( end_time, '%l:%i%p' ) AS etime, ";
$sql .= "TIME_FORMAT(end_time, '%k:%i') AS etime, " . DB_TABLE_PREFIX . "users.uid, fname, lname ";
$sql .= "FROM " . DB_TABLE_PREFIX . "mssgs ";
$sql .= "LEFT JOIN " . DB_TABLE_PREFIX . "users ";
$sql .= "ON (" . DB_TABLE_PREFIX . "mssgs.uid = " . DB_TABLE_PREFIX . "users.uid) ";
$sql .= "WHERE text IS NOT NULL AND (y*10000+m*100+d) >= ";
$sql .= "( ( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13) )";
//OLD LINE  $sql .= "(YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) ";
$sql .= "ORDER BY y, m, d, start_time limit 6";

This is supposed to list the next 6 upcoming events. ITworks with the OLD line, but not with the correct timezone help
Link to comment
Share on other sites

they are fields that hold the year, month and day. Here is sample data:

id uid m d y start_time end_time title                           text
1 1 6 24 2004 22:00:00 00:00:00 Dorian Grey - Rhino Dorian Grey @ Rhinoceros Club - 10pm - no cover
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.