What I cannot seem to work out is how on earth I take a date and deduct a number from it.
So I want to see the records from the last 7 days.
I cant just take the system day and deduct 7 days, or can I?
From what I am reading, I have to create a time stamp and use that. This seems to me to be very long winded for something as simple as deducting days from a date.
I see from some other posts, I am not the only one who has struggled with this.
As answered in Slack: you will need to parse the date into its components and use the os.date() function to convert it to seconds since Jan 1, 1970 at midnight (Epoch or the standard Unix 0 date). Then subtract (7 * 86400) (seconds in a day), then use os.date() to format that new seconds into individual date components.
It seems long winded, but if you do it by subtracting 7 from the day and end up with a negative number, then you have to figure out what that new day is in the previous month (which could be 28, 29, 30 or 31 days long) and then subtract one from the month and check to make sure that didn’t go negative and if it does, change the month to December and subtract one from the year. That’s a whole lot more work with all the if statements you have to write vs:
As answered in Slack: you will need to parse the date into its components and use the os.date() function to convert it to seconds since Jan 1, 1970 at midnight (Epoch or the standard Unix 0 date). Then subtract (7 * 86400) (seconds in a day), then use os.date() to format that new seconds into individual date components.
It seems long winded, but if you do it by subtracting 7 from the day and end up with a negative number, then you have to figure out what that new day is in the previous month (which could be 28, 29, 30 or 31 days long) and then subtract one from the month and check to make sure that didn’t go negative and if it does, change the month to December and subtract one from the year. That’s a whole lot more work with all the if statements you have to write vs: