Storing date and time in a database?

I work on a blog and want to show my posts in the eastern time zone. I decided that saving all UTC would be correct. This creates several problems:

  • I need to transfer all the time from UTC to the east. This is not a biggie, but it adds a lot of code.

  • And the "biggie" is that I use a short time to link to posts, sending a request, ala blogger. The problem is that there is no way to convert the short time of the date to the corresponding UTC date, because I do not have enough information about the time posted.

Hmm, any problem just storing all dates in eastern time? This, of course, would ease the rest of the application, but if I needed to change the time zones, everything would be wrong.

Update

@Jon, I really appreciate your experience, but I decided that the UTC time in the database is incorrect. You may be able to convince me otherwise!

So let me tell you this. I converted all the time to UTC, which required adding much more “syntax” to the “declarative parts of the code”.

What I'm coding is a blog, so I have 2 routes, a list route and a data route. The information route takes a short date and the name of the message, which assumes that the combined will be unique. That is why it breaks. I pass the short route in the request.

Depending on the time of day, we can wrap it around so that it is 29 or 30. Therefore, the short date should be correct, because I do not have enough information in the request to determine how to convert Eastern time back to UTC.

" " DatePosted @12 AM SQL- FirstModified . , , , , . , .

, , . (, ). , ( ), .

, , , .

!

:

  • . UTC, 1. , linq-to-sql, SQL, .

!

+3
4

, - , , , .

- , SQL .

+2

UTC " ". .

, - , . , ? , UTC.

- , , . - , , - , . ( - ).

UTC, IMO.

+5

UTC // , , .

In addition, as others have said, converting UTC to Eastern time does not require “a lot of code”, since you basically subtract a few hours from that time, while remaining a little aware of summer savings.

For example, consider

DateTime currentServerTime = DateTime.UtcNow.ToLocalTime(); 
0
source

Save the values ​​in db in UTC format, and then convert them to local time on the client. Thus, each client sees the time in their local coordinate system, and you do not need to worry about specific time zones.

0
source

Source: https://habr.com/ru/post/1747049/


All Articles