Filter date format Expression

Hello Team,

I am exporting an Excel file that contains data from multiple days. To filter out only yesterday’s data, I have used the following expression in the filter configuration: System.DateTime.Now.AddDays(-1).ToString(“M/d/yyyy”). My question is, will this work if today’s date is 11/25/2023?

Hello @omar_ismail, I think you are right :slight_smile:

If today’s date is 11/25/2023, the expression will indeed calculate yesterday’s date as 11/24/2023, and it will work correctly to filter out data for that specific date.

Cheers!

even if the expression M/d/yyyy not MM/dd/yyyy

Hi @omar_ismail

The expression you’ve provided, System.DateTime.Now.AddDays(-1).ToString("M/d/yyyy") , will work as expected to filter out data from the previous day if today’s date is 11/25/2023.
Here’s how it works step by step:

  1. System.DateTime.Now gets the current date and time, which would be 11/25/2023.
  2. .AddDays(-1) subtracts 1 day from the current date, resulting in 11/24/2023.
  3. .ToString("M/d/yyyy") formats the resulting date as a string in the “M/d/yyyy” format, which would be “11/24/2023”.

So, when you apply this filter expression, it will correctly filter out data from 11/24/2023 (yesterday) when today’s date is 11/25/2023.

Hope it helps!!
Regards,

Yes, It will work @omar_ismail.

Yes, even if you use the format “M/d/yyyy,” it will work correctly.

The format “M/d/yyyy” represents the date in a month/day/year format. For example, November 24, 2023, would be represented as “11/24/2023” using this format. Since you are subtracting one day from the current date, it will correctly calculate yesterday’s date regardless of whether you use “M/d/yyyy” or “MM/dd/yyyy” as long as the format matches the date format in your Excel file.

Cheers!

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