Check if string date is outside time window

I have a bot which checks emails to see if a time period for a certain file upload is within a 3 month window.

Currently I’m assigning an int_variable that sets the value to the current month -4:

Convert.ToInt32(DateTime.Now.AddMonths(-4).ToString(“MM”))

The bot then checks the incoming sting variable to see if it contains a month value of the current month -4.

This works, but my concern is when the month is January, and therefore the current month would be 1, -4 months from that wouldn’t work, or would it? I’m not sure.

I’m certain there a better way to do this, I tried assigning the month name from the month number but then got stuck in a loop of disallowing conversions from int to string.

Any advice would be appreciated.

Thanks

@b.forbes ,

Instead of using the Month number alone you can use the whole date value to compare it against the date to be checked.

  1. Create a variable as “dteFileDate” As DateTime DataType
  2. Create a variable as “dteCompareDate” As DateTime DataType
  3. Then use first assign activity with this
    dteFileDate = DateTime.Parse(“1/5/2012 8:12:14 PM”)
  4. Then use second assign activity with this
    dteCompareDate = System.DateTime.Now.Date.AddMonths(-3)
  5. Then use a IF activity to check whether it is smaller or greater
    dteFileDate < dteCompareDate
1 Like

Thanks, this worked perfectly.

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