I'm trying to build folders to store data pulls. I want to label the folders with the day of that data in the pull.
Ex. I pull 5 days ago data from mysql i want to name the folder the date from 5 days ago.
MySQL can easily handle date arithmetic. I'm not sure exactly how R does it. Should i just subtract the appropriate number of seconds in POSIXct and then convert to POSIXlt to name the folder MM_DD_YYYY?
Or is there a better way?
There is of course a
lubridate
solution for this:is the same as
Other time formats could be:
The answer probably depends on what format your date is in, but here is an example using the
Date
class:You can even play with different units like weeks.
Just subtract a number:
Since the
Date
class only has days, you can just do basic arithmetic on it.If you want to use POSIXlt for some reason, then you can use it's slots: