in reply to Extract data between certain dates using YYYYMMDDHH timestamp

time or gmtime gives you a current timestamp. If you don't care too much about exactness, you can just decrement it by 24*40*3600 to get a date roughly 40 days before.Time::Local converts from a unix epoch timestamp to the usual time tuple. POSIX::strftime is quite convenient for formatting time tuples.

If you want to be exact, you can either use DateTime, or if you want to avoid DateTime, subtract 22 hours worth of seconds from your timestamp in a loop, and exit that loop once the date part of your day has changed 40 times.