I have two DateTimeOffset objects, which return like so when logging them:
TIME 1 (db): 3/17/2016 2:25:37 PM +00:00
TIME 2 (client): 3/17/2016 2:09:19 PM -04:00
TIME 2 < TIME 1? False
I don't want to clutter this with code, but comparison is made like this (as per MSDN):
bool didUserLoginBeforeSysUpdate = clientLoginTime < lastSystemUpdateTimeFromDb;
I think my main misunderstanding comes from whether or not it's factoring in the time zone adjustment (+00:00/-04:00
) in the comparison. My understanding is that it does NOT and compares the raw times as per this SO post.
However, the timezone part is ignored when comparisons are made. In other words, each date time is converted to GMT / UTC and those are compared.
So, in short, what am I doing wrong? Why isn't TIME 2 showing as being earlier than TIME 1?
EDIT:
bool didUserLoginBeforeSysUpdate = clientLoginTime.ToUniversalTime() < lastSystemUpdateTimeFromDb.ToUniversalTime();
var didUserLoginBeforeSysUpdateComparison = clientLoginTime.CompareTo(lastSystemUpdateTimeFromDb);
brkptTIME 1 (db): 3/17/2016 2:25:37 PM +00:00
TIME 2 (client): 3/17/2016 2:09:19 PM -04:00
TIME 1 AFTER UTC CONVERSION(db): 3/17/2016 2:25:37 PM +00:00
TIME 2 AFTER UTC CONVERSION(client): 3/17/2016 6:09:19 PM +00:00
TIME 2(UTC) < TIME 1(UTC) ? False
COMPARISON RESULT - is TIME 2 earlier than TIME 1?: 1 Key: Earlier = -1, Same = 0, Later = 1
Looks like I am misunderstanding how UTC saves. I thought 3/17/2016 2:09:19 PM -04:00
meant that "Universal time is 2:09:19 pm, and the local time where it was stored is 4 hours earlier. Anyway, I need to ask a different question, thanks for the help guys.
false
. So what are you doing wrong? Nothing, except you seem to believe that TIME 2 is before TIME 1. – Guarani-04:00
means that the time zone is 4 hours after UTC, e.g. when the earth rotates it first becomes midnight in the UTC time zone and then after 4 hours have passed it becomes midnight in-04:00
. I.e., that time zone is geographically to the west of the Greenwich meridian. – Guarani