Get the last certain years - dateadd

I am looking to get the last couple of years worth of data that goes back to 1/1/2020 and need this to be the case as I pull the data next month and the month after that, etc. I don't want to have to change the -34 to -35, then -36 and so on to continue getting data 1/1/2020 to 2/28/2023 etc. Each month I refresh the stored procedure I need to keep 1/1/2020 but pick up to then end of the prior month. If I refresh my SP April 2023, I want to see 1/1/2020 through 3/31/2023. If I refresh my SP May 2023, I want to see 1/1/2020 through 4/30/2023. This is the below code I have.
start_receipt_date --between #startdatetime and #enddatetime
between DATEADD(Day,1,DATEADD(MONTH,-34,EOMONTH(DATEADD(Month,-2,GETDATE()))))
And EOMONTH(DATEADD(Month,-1,GETDATE()))

Related

Automate end date depending on session type (=duration in calendars days), start date AND if bank holiday?

I am developing an automated calendar for a school on AirTable, but I am struggling to add if there is a bank holiday between the start date and end date. If the bank holiday falls on a weekday, it needs to add +1 day to the end date.
I have created a "bank holiday" table, as well as a full calendar table (containing everyday of the year and what weekday it falls on).
I'd like for the user to have the end date generated automatically by only writing the start date.
For example:
I have a session starting on Monday, 7th of march. The "session type" would be "Course 1", which has a duration of 10 days (two weeks, monday to friday - I don't know if the duration should be 14 days instead?). If there's a bank holiday in the 10 days after the start date, and it's on a weekday, it needs to add +1 to the end date. If the end date falls on a sunday, it needs to add +2 so that it ends on a Monday.
The course is divided in multiple classes, it would also be awesome to have a timeline view with the full Course and all the classes.
Here are some screenshots of my tables :
I know there is a possibility to write a script in Python with an AirTable API... but is there an easier way ?
I've dealt with a problem like this before: when an event happened in relation to other events mattered.
You'd think by the use of the words "in relation" that you could deal with this in a relational way, but I see it as a rule:
If Event A happens at Time 1, and it's so much or so little time from Event B, then do with Event A...
And, again by my way of thinking, rules are expressed in code.
And if you actually even can express that with a relation, I think it'd be very convoluted.
So, for your problem, you need to encode every schedule-able day that's 10 working days or less before a Bank Holiday (BH) so that if the day is selected you know it's less than 10 days from a BH and can conditionally add another day to the end date.
I looked at your examples, and here's my solution. I have a Calendar table which has all days, and two supporting "Bank Holiday" fields: does the date fall on a BH, and if not, is the date 10 days or less from a BH. We're looking at my All view, here:
I also have the view, Weekday, not bank holiday, and that's the view that you can pick a day from to schedule an event from the Event table.
The Event table:
You pick a day from the Start day field. Start day < 10 work days to Bank holiday? is a lookup field from the Calendar table for that day. End day is this formula:
DATETIME_FORMAT(
DATEADD(
{Start date},
IF(
{Start day < 10 work days to Bank holiday?},
14,
13),
'day'),
'ddd, MMM Do')

I have to delete 30 days old data based on timestamp in DB2

I have a requirement to delete 30 days old record in DB2. I used below code to delete, It worked fine but current timestamp keep changing. This cause my procedure to go on loop.
DELETE FROM TABLE
WHERE TIMESTAMP_FIELD < CURRENT TIMESTAMP - 31 DAYS
I'm using my procedure as generic delete, So I will not able to use host variable. I tried subdate ADDDATE but no luck.
Please help me out.
Thanks
Current Timestamp is constantly changing so you're liable to chase your own tail if you use it for comparisons down to the microsecond level.
If you need a less precise value to use for deletions you can cast the current date - 31 days together with '00:00:00' (midnight). This value will only change when the current date does so your results are more predictable.
DELETE FROM TABLE
WHERE TIMESTAMP_FIELD < TIMESTAMP(CURRENT DATE - 31 DAYS, '00:00:00')

When making an API call to omniture (site catalyst) , is there any way to use rolling dates

i have created a dashboard in klipfolio and only need 52 weeks data to be fetched by the api with respect to current date .. currenlty i m manualy passing date but i want it to use the system date to automaticall fetch data for me
"dateFrom": "2018-01-10",
"dateTo": "2018-02-05",
You can use Klipfolio's date parameters to accomplish this. In your example, you want the last 52 weeks from today so your query for dates could look like this:
"dateFrom": "{date.addWeeks(-52).format()}", "dateTo": "{date.today}",
Alternatively, if you want it to start on first day of the week 52 weeks ago, your query for dates could look like this:
"dateFrom": "{date.addWeeks(-52).startOfWeek.format()}", "dateTo": "{date.today}",
This will create a 52 week rolling window relative to today so you will not have to update your query every week.

How To Parse Date and Time from Tweets Listed in a Google Spreadsheet

I have over 5,000 tweets in a spreadsheet. I copied them from another site and each one looks like this:
Josh Mitchell #mitchellmadnessTue Dec 16 22:24:27 +0000 (GMT) via Twitter Web Client0
Are you ready to party for the holidays and network your mistletoe off? #wickidpissa #elevate #publicityhttp://t.co/IoovyowZYO
That whole thing is in one cell, A2. The first line in that cell has the date and time. The second line in that same cell is the tweet, which we can ignore.
I want to be able to parse out the date and time from each cell in column A and put them into columns B and C, respectively. In the first line of each cell, the twitter handle and week day have no space between them. So in the example above, the day would be Tuesday and the time would be 22:24:27. Throughout the list of tweets, the days are represented as "Tue", "Wed", "Thu", etc.
Is there a formula or script I can run to easily capture this information across all of tweets in each cell?
Seems, say in B2 [not per spec, for the second formula!]:
=mid(A2,find("(GMT)",A2)-22,15)
is deemed "fit for purpose".
To convert that to a date/time index (ignoring time zone issues etc and assuming the year is 2014):
=value(mid(B2,5,2)&"-"&left(B2,3)&"-2014")+right(B2,8)
With a date/time index the results could be copied into a different column and formatted so one shows date and the other time.

Store a day of week (mon, tue, wed, ...) in rails db and compare with the day of today

I am developing a rails 3.1 app where I need to store opening hours for stores. I want to store opening time, closing time and the day of the week. My first idea is to store a day number where 1 is monday and 7 sunday but is there a better approach which is more suitable when I want to internationalize my application?
If i store the day number, how can I compare it with the day of week today to check if the store is open or not?
Thanks for any help
Sounds like you're on the right track. To figure out the current day of the week:
Date.today.wday
Although that considers Sunday 0 and Saturday 6.
A number value should be fine. Use the numbers used by the Ruby Time class to keep things simple: http://www.ruby-doc.org/core/classes/Time.html#M000369
Sunday will be 0, Monday 1, etc...

Resources