EST DB DateTime to GMT AWS cloud DateTime compare

beantownace

Active member
Joined
Feb 15, 2019
Messages
40
Programming Experience
5-10
Hello gurus,

I got a question hoping someone dealt with this. I am comparing a database stored EST datetime to GMT based DateTime.Now where I ran into a problem realizing that the DB value is EST and when deployed via AWS seems to be GMT even on us-east-1. What is the best way to handle that compare as I need to make sure a datetime date only is today.

Current code is:


DateTime Compare:
if (DateOnly.FromDateTime(db.SubmittedDate) != DateOnly.FromDateTime(DateTime.Now))
{
    //do stuff
}

Thanks all for any suggestions best way to do this in C#. The SubmittedDate is EST and DateTime.Now is coming in as GMT when deployed to AWS.
 
What is the value of db.SubmittedDate.Kind? Assuming that it is set to Utc or Local then you can always compare with db.SubmittedDate.ToUniversalTime() with DateTime.UtcNow.
 
What is the value of db.SubmittedDate.Kind? Assuming that it is set to Utc or Local then you can always compare with db.SubmittedDate.ToUniversalTime() with DateTime.UtcNow.

Good question. So it is coming in as a string actually so the Kind is Unspecified I have to do a convert I missed that:
DateOnly.FromDateTime((DateTime)db.SubmittedDate)
 
Since you are parsing a string, this might help:
 
Back
Top Bottom