How to compare date grabbed by get text activity to date 48 hours before (2 days ago)

Hello,

As the title states, what methods / activities might be helpful to compare a date grabbed from a get text method, in the form of this: 8/20/2018 6:28:59 PM

This is being stored in a variable, dateGrabbed, as a generic value. How would I then take this value and compare it to a date that is 48 hours less than itself? For example

If dateThatIsTwoDaysLess < dateGrabbed… Do something.

Noting that dateThatIsTwoDaysLess is always changing depending on the date grabbed.

Any insight on a helpful activity or method would be awesome! I am good with the logic and can probably get my way around if anyone can offer some guidance. I thank you in advance!

Hi @developer120
Welcome to the community forum!

The simplest way to accomplish this would be to use an if activity and check the date compared to current - 48 hours:

dateGrabbed > now.Subtract(48:00:00)
2 Likes

You can also do DateTime.Now.AddDays(-2) instead of now.Subtract(48:00:00). It might be a little more readable in some cases. @nlee1131’s answer does the same thing by subtracting 48 hours.

2 Likes

Awesome, thank you! Also thank you for the warm welcome!

1 Like

Huge help, thank you! I want to remark when I first did this the dates were comparing wrong. The if statement was saying that a 2018 date was greater than a 2019 date. Well for any future adventurer reading this, remember to make sure both variables are of type System.DateTime lol. Thanks again!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.