I have a string with a value in the format of
dd/mm/yyyy
Now I want to compare that to another string and check if they are equal, the other string can have the value of
dd/mm/yyyy
or sometimes when the day is between 1 and 9:
d/mm/yyyy
Sometimes when the month is between 1 and 9:
dd/m/yyyy
So there are a couple of instances where the string isn’t equal but the actual date is.
First I only saw that in some cases when the day is between 1-9 it doesn’t start with a zero so I did:
createdDate = dateField.value.ToString().Substring(0, 10);
createdDate = createdDate.Trim();
if (createdDate.Length == 9)
createdDate = "0" + createdDate;
but then I saw that it can be the same for month so there must be a better way to check this?
Why not just parse both, one with the format string “dd/MM/yyyy” and one with the format string “d/M/yyyy” and compare the returned
DateTimevalues? After all, the date being represented is the important part, not the string representation, presumably.