Hello, I’d need to match two strings that contain two dates. They should be like these: “dd/MM/yyy”. I manage to format in that manner but then when i write dt2.trim = dt3.trim they seem not too match even though they have the same text.
However, One(dt3) is already structured like that whereas the other(dt2) had to be formatted.
What I tried was the following:
assign:
dt2(string) = Datetime.ParseExact( dt1, “yyyy/MM/dd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)
then i compare with what I have written. But seems to fail.
Any help?
thank in advance,
Alessandro
Could you please explain more? dt.1 (which then become dt2) is in this format “yyyy/MM/dd” so what i thought was to convert it datetime and then to string but with the dd/MM/yyyy format. i Thought was forced to tell the original formatting (yyyy/MM/dd) first and then to what i want to convert it to. So i cut just the last part of the code and use parse also for the other string?
Datetimes hold a value (milliseconds since 1970), there is no format. You only format it when you want to see it or use it as a string. When you have “1/22/2023” in a string, the system doesn’t see it as a datetime. It’s not processed as a datetime. It’s just a string of characters.
Convert your strings to datetime, and compare your datetimes - that way you’re comparing the values of the datetime.
About common / quasi standards lets be a little bot more clean for the variable name. If wanted then use str Prefix for indicating that it is a string like strDate1, strDate2
about dt (a good prefix for datetime but also often seen for DataTable) setup your own coding standards
So lets begin:
this sounds like you want to to check if tow strings are equal.
similar as
same as A-a we are leaving the string compare when it is about date string when:
occurence within different formats
strict compares as < = > … as we want to compare dates and not fail on lexically compare
it is nothing else different as a string is equal string (A A example) within another datatype
Coming back to the issue
When an implementation fails on the first round, then lets debug it, get paused by breakpoint and inspect the variables.
so in your case we would ask you to give us immediate panel output of the two input source strings (our naming strDate1, strDate2). Maybe only a trim or other small thing is confusing the compare
Also feel free to prototype your ideas directly in your imediate panel.
BTW: we asked a DateTime variable on the life before the Unix Timestamp Birth and got back following feedback: