Could existence be produced simpler by saving DateTime values like a long rather? There always appear to become problems whenever using null DateTime values, whether storing or locating - null DateTimes, invalid DateTimes, etc. will always be a discomfort to utilize.

Will it be better to simply make use of a long data type since always produce a DateTime in the ticks?

Edit: Sometimes with SqlServer and MySql. SqlDateTime is really a .internet derivation of DateTime. You will find variations between all 3 platforms of the items a legitimate DateTime is. How can you handle these variations?

I suppose that's lower to non-public preference. I usually use datetime types and haven't any make use of them.

Should you store them as longs though semantically they're no more dates. Should you ever desired to perform a query to choose all accounts added on the Friday (say) you would need to jump through several hoops to operate that out.

I can not think about any outstanding reason personally, databases support DateTime's themselves, and storing them like a lengthy you might finish up shooting yourself within the feet. Let us say you have to have the ability to operate a query "Get me all rows between 3 AM and 6 PM" - should you store them as ticks, you will have to convert to a DateTime within the database.

Storing them as ticks may slow down a number of other procedures, for example grouping, sorting, blocking, etc.

For those who have nuances with DateTimes within the database, for example TimeZone, it's strongly suggested to normalize the DateTime to some specific timezone, for example UTC. Many of the issues that teams face with DateTime within the database is frequently because of unclean input, like not normalizing the TimeZone. Storing it as being ticks will still have a similar problem.

No, make use of a datetime column.

There always appear to become problems whenever using null DateTime values

In case your column is nullable, and also you for whatever reason have difficulties when the kind of the column is datetime additionally, you will have problems when the kind of the column is long.

... invalid DateTimes

How can you get invalid datetimes right into a datetime column? Among reasons of utilizing the datetime column to start with is the fact that kind of validation happens prior to the information is permitted to become placed. More likely you will get invalid datetimes when utilizing a naked long.

Finally, utilizing a long implies that viewing your database via simple SQL (select * from table) will produce unreadable results.