I have a website which was located in UTC + 1 (The SQL SERVER).

I have migrated the website, and now I have in UTC - 8(The SQL SERVER).

So I have 9 hours of difference.

I have an automatic publication of post based in the beginning of the day.

So I usually post one post each day at 0.00 in UTC + 1 , but now it is publishing 9 hours later...

All my select clauses end with:

select id, title, content 
from articles 
**where dateScheduled <= getdate()**

If I wanted to publish a post the 25 of January, I need to wait until it is 25 of January in the UTC - 8, but I want to be publish 9 hours earlier==> when it is 25 of January in UTC + 1.

What do you think that it can be the best way to do it?

Thank you very much!!

有帮助吗?

解决方案

I'm a bit confused on what you're asking. Are you trying to post these records at midnight local time instead of midnight UTC time?

Have you looked into something like this:

DATEADD(hh,DATEDIFF(hh,GETUTCDATE(),GETDATE()),dateScheduled)

The DATEDIFF pull how many hours local time is away from UTC + 0 time and then add that difference to a date column. This is useful if your timezone practices DST so you don't have to change a hard coded -8 value.

Let me know if this helps. If not, clarify what you're trying to do and I'll look at it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top