Last post Jul 18, 2017 12:03 PM by ARoshanzamir
Jul 17, 2017 08:21 AM|ARoshanzamir|LINK
I have two variable of DateTime , the first one is updatedAt and the secend one is modifiedSince
When I compare them in if condition it should return true instead of false;
(it returns false);
thanks in advance
Jul 17, 2017 08:30 AM|PatriceSc|LINK
Have you tried to inspect those variables to show for example the Ticks property? My first thought is that you mabe have a difference beyond the second.
Jul 17, 2017 03:55 PM|codemovement.pk|LINK
They might be in different data types.
Will you please apply following on both dates before comparison?
Jul 18, 2017 06:11 AM|Jean Sun|LINK
As I can see in your image, the two time have the same year, month, day, hour, minute. However DateTime has a lot of precision, could you please click '+' and check the exact time, such as second and millisecond. As you can see in my sample below, the two
time's millisecond are different, so they're not the same.
If you only want to compare the two time without millisecond, you need to do some conversion for time. You can use ' ToLongTimeString() ' to get its equivalent long time string representation. The standard long time pattern is "h:mm:ss tt". Then convert
the processed time to the DateTime type. My sample is as follows, you can take it as a reference.
public bool Test()
DateTime updatedAt = DateTime.Now;
DateTime modifiedSince = DateTime.Now;
DateTime new_updatedAt = Convert.ToDateTime(updatedAt.ToLongTimeString());
DateTime new_modifiedSince = Convert.ToDateTime(modifiedSince.ToLongTimeString());
if (new_modifiedSince <= new_updatedAt)
For more information about ' ToLongTimeString() ', please turn to
Jul 18, 2017 12:03 PM|ARoshanzamir|LINK
Hi Jean Sun;
Thank you so much for replaying ; It was exactly my problem ;
wish you all the best