Criteria to filter for "yesterday" from general date/time format

JamieD

New Member
Joined
Nov 26, 2012
Messages
8
The field that I am trying to filter within is date/time in the following example format:
9/1/2015 10:00:00 AM

I need to filter for "yesterday", which I know should be "date()-1", but for some reason this isn't working. It seems like the solution should be simple, but I'm having difficulties identifying it.

Please help! :)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Your problem is that your field is date/time. Your example will minus one day from Date(), but not when the date value contains a time component. If you don't need the time in the table, I'd eliminate it - it causes issues, as you can see from your situation and one I point out below.

DateAdd("d", -1, [YourDate]) should go back a day, but I don't know how to advise you to use it (=, >, >=, Between, etc.) since I don't know exactly what you are doing. As I've posted in this forum before, date/time fields cause issues with the Between operator and need special handling. If you specify BETWEEN 01/01/2015 AND 01/15/2015, the results will be cut off on the fifteenth at 00:00:00 (i.e. you will not get 1:00 A.M. for example).
 
Upvote 0
I just wanted to throw this out there for future reference.

Since time was part of the data (9/15/2015 8:00:00 AM), I couldn't use "date()-1" because I kept getting zero results. The reason being is with time in this format, technically the date starts at zero and goes to 2400 (essentially). So when I used "Between date()-1 AND date()", my results were all records throughout "yesterday".

@ Micron - Thank you for your suggestion, I really appreciated you taking the time to help! :)
 
Upvote 0
'K, you didn't say you were using the Between operator. In those cases, you use the DateAdd function on the second date and add however many intervals (such as minutes or seconds) you think you need. For example, it would be something like "Between Date1 and DateAdd("n",1439,Date2)" to add 23 hours and 59 minutes to the second date (from the zero hour point).

And no problem - glad to help and like to hear whether or not something I suggest works.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top