Fetch messages older than certain date

I'd like to fetch the most recent messages from a channel that are older than a specific timestamp. E.g. if my limit is 5 days, I want the most recent messages that are at least 5 days old. I noticed the FetchMessagesOptions object has the before parameter, but it works with a specific message ID, not a timestamp.

Do I first need to get the oldest message that is less than 5 days old, and then use that message's ID as the before value? Because I'm not sure how I could do this efficiently without unnecessary API requests. Or is there a better way?
Was this page helpful?