I have a WinForms application that was written in C# .NET 3.5. This application interacts with a SQL Server 2008. Whenever I add a record into the database, I have a DateAdd
column that I insert DateTime.Now
into. For whatever reason, I have 4 records 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'
The records before and after these all have proper dates of '2011-05-29 XX:XX:XX.XXX'
. Users have no access to modify the date fields in any application.
Is there any reason that the dates would change like this? Users have no access to modify their system time, which I'm assuming is where DateTime.Now gathers the date from.
Basically, I've come to the conclusion that there is either a bug, or a user has a Delorean fully equipped with a flux capacitor...
If this is a client windows app, check the system time on the machines that the users in question are using. Also, I don't know if this is best practice or not, but I find it easier to maintain if I use GetDate() in SQLSERVER rather than passing the date from the C#.NET application in cases were I need to record the current time.
The motherboard battery on one of your users computers is dead - look for the "Windows 98 Compatible" sticker on the front of a (now) yellow Compaq desktop under someones desk. That computer was powered on 2 days before writing a record to your database. The next time it is completely shutdown or power cycled it will go back to Jan 1, 1980.
Best practice would be to have the database assign the date (set the column default as GETDATE()). This way a single date scheme is used and you don't have to worry about users changing dates, events from different users appearing in the wrong order because their computers where a few minutes off one another, or the times being several hours off because of incorrect timezone settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With