Build a dynamic query

Hi,

We have to build a dynamic query for deleting the last month's records in System Administration > Ongoing Maintenance > System > Purge/Archive.

Suppose its incident, how are we going to build it?

BR,

Haniyya Rehan