It is my first post here and I thought it really fits on this side than on the regular website.
I am sure many of you (programmers) must have had nightmares with this Date 'object', either in your early days or in some code you are inheriting from someone. Let's just assume there are more programmers in then rest of the world (6.6 billion) than in the US (0.4 billion)! :)
So, if you are programming from outside the US, you most likely have a date format different from the default computer (US) format, ie, different from 2019 11 28 02:03:04. So a lot of the times, you got this date wrong: 11 04 2019... well it is 11th April for 'most of us', and 4th November for Americans.
I thus, decided, against what all programmers here may scream against, that I will declare my dates as string:
Dim StartDate As String = String.Empty
This works wonders for me because when I send my dates to the database (Access, SQL CE, SQL Server, MySql, ie, the databases I ever program against), I send them as String, thus: '11 Apr 2019'. Replace ' with # for Access.
All my databases are happy. All my programmers/partners are happy reading the code, there is no confusion about 11 Apr 2019.
This works great for Create, Retrieve, Update (you can add Delete).
So my question is, why do we have to be 'conventional' and declare our variables as Date, when that is causing most of the world a lot of trouble?
Is it thus possible to create a new data type that will take care of this, so that it is not String, as I'm sure a lot of you will protest against my use of String?
So while this appeal is pending, I continue to display dates in all my applications as:
Start Date: 29 Nov 2019
, which Germans and Americans will be slightly annoyed about, but be able to read without any ambiguity, and send them for search/update/insert as
StartDate = '29 Nov 2019 00:00:00'
I know there are Regional and Globalization classes to use, but in Africa (1.2billion), a huge chuck would not even set their computer regions right. Please don't think they way you are thinking: internet is still an invention out there for the majority - penetration rate on PCs is barely climbing to 10%!
My 'ComplexDate' data type would be one that requires month part of the date to be specified in String, as you have seen in my examples above. So that we are all clear on which date this post was made! eg, Nov/2/2019, 02/Nov/2019, 2019/Nov/2, 5 Nov 2019, etc
04 Nov 2019is less ambiguous than11/04/2019, but it is still ambiguous. Depending on the timezone,04 Nov 2019 23:30:00and05 Nov 2019 00:30:00may be the same point in time. Using a concreteDateclass allows you to add a field with the offset to UTC, which would resolve all ambiguities. And then it does not matter whether you store the month as string or as integer (or as enum)."I continue to display dates in all my applications as [...]". Display and internal representation aren't directly related. You can display strings using whatever format you want and store them in an entirely different structure.