DateTime.Now Strange Date Returns

I have a WinForms application written in C # .NET 3.5. This application interacts with SQL Server 2008. When I add a record to the database, I have a DateAdd column into which I insert DateTime.Now into. For some reason, I have 4 entries with odd dates:

 '1980-01-03 23:08:43.970' '1980-01-03 23:08:44.157' '1980-01-03 23:08:44.530' '1980-01-03 23:08:45.547' 

Entries before and after all of them have the correct dates '2011-05-29 XX:XX:XX.XXX' . Users are not allowed to change the date fields in any application.

Is there a reason why dates will change this way? Users do not have access to change their system time, and I assume that DateTime.Now collects the date from.

Basically, I came to the conclusion that there is either an error or the user has a Delorean fully equipped with a flow condenser ...

+6
source share
2 answers

If this application is for client windows, check the system time on the machines that users use. Also, I don't know if this is best practice or not, but it’s easier for me to support if I use GetDate () in SQLSERVER instead of passing the date from a C # .NET application in cases where I need to write the current time.

+6
source

The motherboard battery doesn’t work on one of your computers - find the “Windows 98 Compatible” sticker on the front panel (now) of the yellow Compaq desktop under someones table. This computer was turned on 2 days before writing a record to your database. The next time he shuts down completely or turns on, he will be back by January 1, 1980.

It would be best practice to set the database date (set the default column as GETDATE ()). Thus, a single date scheme is used, and you do not need to worry about users changing dates, events from different users appearing in the wrong order, because their computers are located a few minutes apart, or the time allotted for several hours due to incorrect time zone settings.

+3
source

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


All Articles