Search code examples
vbaoutlookoutlook-2010

Can I use the dateadd function to specify a time the day before


Each time I run a macro, I want it to move emails that were received before 10pm yesterday. I can get it to work for a time relative to NOW (e.g. 2 days ago, 4 hours ago) but this macro can be run at any time of the day and I want it to always check for emails that were received before 10pm yesterday. Can I adjust the code below to do so? thanks in advance!

If .ReceivedTime < DateAdd("d", -1, "Now") Then

Solution

  • You could just add to yesterdays date, exclusive of its time:

    if .ReceivedTime < dateadd("d", -1, date) + timeserial(22, 0, 0) then