Get last day of month :: Expression language evaluation error :${coord:dateOffset(${coord:endOfMonths(0)}, -1, 'DAY')}: - oozie

I want to get last day of previous month and don't understand where is the error
<value>${coord:formatTime(${coord:dateOffset(${coord:endOfMonths(0)}, -1, 'DAY')}, 'yyyy-MM-dd')}</value>

Related

R: 'strptime' fails to parse output from 'format'

Let's say I have some date variable which I convert into a string in given format:
mydate <- as.Date("2021-01-01")
myformat <- "%b-%Y"
formatted_date <- format(mydate, myformat)
formatted_date
[1] "Jan-2021"
Now that I've converted it to a string, I then try to read it back to date with the same format, but it does not succeed:
strptime(formatted_date, myformat)
[1] NA
As per the R documentation:
For strptime the input string need not specify the date completely: it is assumed that unspecified seconds, minutes or hours are zero, and an unspecified year, month or day is the current one.
Adding the day at the beginning with %d or similar will make it work, but the docs say it shouldn't be necessary.
Am I missing something?
The complete doc reads :
For strptime the input string need not specify the date completely: it is assumed that unspecified seconds, minutes or hours are zero, and an unspecified year, month or day is the current one. (However, if a month is specified, the day of that month has to be specified by %d or %e since the current day of the month need not be valid for the specified month.) Some components may be returned as NA (but an unknown tzone component is represented by an empty string).
Specifically, the important part here is (However, if a month is specified, the day of that month has to be specified by %d or %e since the current day of the month need not be valid for the specified month.)

Teradata Case Then Set Time Interval

I have a Teradata query where I subtract two TS fields to get the delta in minutes.
I then want to test another field using CASE, and return either the delta TS above or a defined interval.
However, I am getting a 7452: Invalid Interval error with the following code:
(TS2- TS1) day to minute as TS_DELTA,
case when TIME_CATEGORY in('0-3 HOURS','3-8 HOURS')
then TS_DELTA
when TIME_CATEGORY = 'NEGATIVE'
then interval '0' minute
when GROUND_TIME = '> 8 HOURS'
then interval '5' minute
end as SUM_TIME
I have another CASE that defines TIME_CATEGORY, that works fine. I've narrowed down the error to the
then interval '5' minute
which I can't figure out what's going on. Any ideas?

Teradata - Calculate the previous quarter date start date and end date from current date

I have current_date in Teradata which 18 DEC 2019
I have to calculate the previous quarter start date and end date from the above current_date.
Input = '2019-12-18'
Output Start Date = '2019-07-01'
Output End Date = '2019-09-30'
You should be able to do this using the TRUNC function, something like:
SELECT
TRUNC(ADD_MONTHS(CURRENT_DATE, -3), 'Q') AS Start_Quarter, -- Previous quarter start
TRUNC(CURRENT_DATE, 'Q') - 1 AS End_Quarter -- Current quarter start date - 1 day
Give it a try and let me know. This assumes the mistake in the manual is still considered a "mistake".
Also, depending on what TD version you're using, you may be able to use built-in functions:
SELECT
TD_QUARTER_BEGIN(CURRENT_DATE) AS Start_Quarter,
TD_QUARTER_END(CURRENT_DATE) AS End_Quarter
Reference
TD Manual
Built-in functions

Unable to generate sequence of dates by quarter properly in R

I would like to generate a sequence of dates by quarter backwards from a given date (31 July 2015). Instead of getting the last day of April, I get the first day of May as below:
> seq(as.Date('2015-07-31'), as.Date('2014-09-30'), by = '-3 month')
[1] "2015-07-31" "2015-05-01" "2015-01-31" "2014-10-31"
I also tried passing -quarter in the by option but I got the following error:
> seq(as.Date('2015-07-31'), as.Date('2014-09-30'), by = '-quarter')
Error in seq.Date(as.Date("2015-07-31"), as.Date("2014-09-30"), by = "-quarter") :
invalid string for 'by'
While I can check the day of the month and correct accordingly should the dates have been over-adjusted into the wrong month, I was wondering if there exists a parsimonious snippet of code to do the above?
A quick fix would be to take the first day of the following month and substract one:
seq(as.Date('2015-08-01'), as.Date('2014-10-01'), by = '-3 month') -1
[1] "2015-07-31" "2015-04-30" "2015-01-31" "2014-10-31"

SQLite : obtain current week

I'm trying to obtain the current week for date comparison in SQLite.
I have no problem for last month, last year, today, yesterday... but don't find the solution to have the current week.
I tried lot of things like:
SELECT tastings.* FROM tastings
WHERE (DATE(tastings.date) > DATE('now','weekday 1','+ 7 days'))
Can you help me ? Thanks.
This code gives you the week number where the first day of week is monday. It also works well for last and first weeks of the year.
strftime('%W', 'now', 'localtime', 'weekday 0', '-6 days')
I guess you want compare 2 date, Assume you have a table named _testTbl and have 3 column _id INTEGER, _name TEXT, _recordDate TEXT
you want name that record this week
you can use below code:
SELECT * FROM _testTbl
WHERE _recordDate > datetime('now', 'start of day', 'weekday 6', '-7 day')
note that this week start by saturday (sunday 0, monday 1, ..., saturday 7)
this t-sql means:
datetime is a sqlite date and time function.
first parameter is given time: 'now' means the current time.
second parameter take the time to start of day.
third parameter take time to the next weekday number (in this case, saturday).
fourth parameter take time to start of week
What is stored inside the tastings.date column? Note that SQLite does not have “timestamp” type affinity, so probably you store Text (some representation of the date) or integer (julian day, epoch…)
All time and date functions expect a valid time string and convert that time string to another string format. If tastings.date contains a week number then use:
AND cast(tastings.date AS TEXT) = strftime('%W','now')
This helps me to compare the 2 dates using the week of the year.
AND ( strftime('%W', tastings.date) = strftime('%W', 'now') )
Thanks you.

Resources