Some date missing when extracting mails

akika

New Member
Joined
Aug 2, 2018
Messages
11
Office Version
  1. 2016
Hi
am extracting some range of mails based on date. however, am not getting all mails
01-Dec-24 to 15-Dec-24. I cant hardcode the date as range can vary.

for 01 dec mails after midnight to 05am are not retrieved and for15 dec after 11am are not output in file.

VBA Code:
    startdate = Format(DateAdd("h", -myUTC, _
    CDate("01/" & Month(themonthyear) & "/" & Year(themonthyear) & " 00:00:00 AM")), "'m/d/yyyy hh:mm:ss AM/PM'")
    enddate = Format(DateAdd("h", -myUTC, _
    CDate(DateSerial(Year(themonthyear), Month(themonthyear) + 1, 0) & " 23:59:59 PM")), "'m/d/yyyy hh:mm:ss AM/PM'")
 
Not much there to go on. Did you step through the code and check your variable values as you go? I suggest you verify they are what you think they are.

Maybe not the cause and maybe you know this, but the Format function converts values to strings, so I imagine that whatever you do with the dates after that, you'll be passing a string to some other code or function. This is the output if I substitute Date() for themonthyear and 1 for -myUTC:
'3/1/2025 12:59:59 AM'
'1/2/2025 01:00:00 AM'

I would think you'd need date delimiters (octothorpe) for dates and not single quotes:
#3/1/2025 12:59:59 AM#
#1/2/2025 01:00:00 AM#
 
Upvote 0
Il problema potrebbe risiedere in DateAdd("h", -myUTC, ...) se myUTC sposta l'intervallo. Controlla myUTC, usa Debug.Print startdate, enddate e controlla il formato della data in Outlook.
 
Upvote 0
sorry, in english

The problem may be in DateAdd("h", -myUTC, ...), if myUTC shifts the range. Check myUTC, use Debug.Print startdate, enddate and check the date format in Outlook.
 
Upvote 0

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