Why doesn't C# have a "Date" type?

Something I've been musing today - writing an application that needs the user to pick a date, which needs to be stored solely as a static date, without any need to apply any adjustment when displayed in different time zones.

My JavaScript date picker returns a date (e.g. 2021-08-01), but by the time my WebAPI controller has parsed that, it gets interpreted as 2021-08-01 00:00:00 BST (British Summer Time).  What's the problem with that?  Well when you then later fetch the date, if you use it to create a new Date() object in JavaScript, it converts it to the user's local time zone.  Depending on the time zone the client is located in, it might mean a date you input as 1 August 2021 could end up being displayed as 31 July 2021 instead.

If its something like a conference taking place somewhere in the World - that conference is always going to be on the date the user has input - there's no need to adjust that date so it shows as the day before in a specific time zone (because its not taking place in that time zone).   

This made me think - why is there a DateTime type, but not a Date type?  MySQL for example has both.

My way around it?

I could store the date as string.

However, I prefer to have it stored as a DateTime type, in case I need to query or filter using it.

I make sure the JavaScript date picker always stores (and therefore sends to the WebAPI controller) the date in UTC format - e.g. for 1 August 2021 "2021-08-01 00:00:00Z".

When outputting the date (or before loading it in to a fresh instance of the date picker) - I parse it to make sure I'm starting with the UTC values (e.g.  getUTCDate, getUTCMonth and getUTCFullYear of the JavaScript Date class).

It's good to have a couple of computers, where you can set the time zone in Windows to be somewhere far, far away in order to test this stuff works OK.

But I'm also open to better suggestions.

Comments