extract 2 days of previous data and exclude weekends in pl/sql - plsql

Looking assistance in PL/SQL query.
Business Case:
Extract 2 previous business days of data from DATE column excluding weekends.
(Business Days - Monday to Friday)
End users are going to provide only 1 date to extract data.
Example:
If Effective_date is on Monday, then need previous 2 working days data of Thursday and Friday.
If Effective_date is on Tuesday, then need previous 2 working days data of Friday and Monday.
If Effective_date is on Wednesday, then need previous 2 working days data of Monday and Tuesday. and so on.....

Related

Can I define exact weekday in iso8601 datetime to schedule a job?

The date-time that i have now:
"schedule": "R/2017-10-05T17:21:00/PT15M"
for now the job is scheduled for every 15 minutes (in chron), but if i want to perform it three times a day at a certain time and only Monday - Friday?
Is it possible to define in this format?
It's not possible
ISO8601 is designed to define intervals but only static. There is no way to define weekdays or weekends. This means you can only define interval for 3 times a day but not every day from Monday to Friday because then you will have not equal intervals between Friday and Monday.
What you can do is to create 15 jobs scheduled weekly.

How to find a previous weekday (Sunday, Monday, etc.) from a specific date using Momentjs

I'm trying to figure out how to build code that will find the 'MM/DD/YYYY' date of a previous day of the week in relation to a given date, which is 04/10/18.
If I've understood Momentjs' documentation correctly, I think I can use negative weekday numbers to find a past 'X-day' from a specific date.
I know the date I'm using is a Tuesday, so I thought if I gave the weekday function the numerical representation of last Tuesday (-2), I would get the past Tuesday, '04/03/2018'. The problem is that when I run the following check:
expect(await moment('04/10/2018', ['MM/DD/YYYY']).weekday(-2).format('MM/DD/YYYY')).toBe('04/03/2018');
I get a result of '04/06/2018' instead.
The returned value is correct. The function .weekdays(-2) computes two weekdays earlier than the given moment.
In your example, two weekdays before a Tuesday would be a Friday, because one weekday before Tuesday is Monday, and one weekday before that is Friday, so Tuesday 4/10/2018 - 2 weekdays = Friday 4/06/2018.

How to calculate end of week in SQL?

Given a date format yyyy-mm-dd, how would I calculate the saturday at the end of the week? For a sunday, I would like to calculate the saturday of the following week. I am using teradata 15.
When you run the query on Saturday do you want to get the same day or the next Saturday?
next_day(date-1, 'sat') -- same day
next_day(date, 'sat') -- next Saturday

Epidemiological curve using R and epitools gives wrong epiweeks

I have been trying to make epidemic curves in R with the epitools package. According to the documentation, you can automatically generate epidemiological weeks from a date variable, similar as I have been doing for long in STATA. Fyi, epidemiological weeks are different from yearly week numbers:
The first epi week of the year ends, by definition, on the first
Saturday of January, as long as it falls at least four days into the
month. Each epi week begins on a Sunday and ends on a Saturday.
http://www.cmmcp.org/epiweek.htm
https://wiki.ecdc.europa.eu/fem/f/1287/p/576/681.aspx#681
graphlabels<-epicurve.weeks(DATE_variable,
axisnames=FALSE,
xlab = "Week of Year",
ylab = "Cases per week",
tick.offset = 0.5,
col=mypalette)
axis(1,
at = graphlabels$xvals,
labels = graphlabels$cweek,
tick = FALSE,
line = 0,
)
This automatically generated a nice curve:
"Hurray!!", I thought. But, alas, being a scientist I double checked the data using STATA as well as manually and noticed that the data does not correspond!
Am I doing something wrong with epitool package that it gives me wrong epic weeks?
After some further discussion and research, there are differences in how epidemiological weeks can be calculated.
EPITOOLS as.week
In public health, reportable diseases are often reported by 'disease
week' (either week of reporting or week of symptom onset). In R, weeks
are numbered from 0 to 53 in the same year. The first day of week 1
starts with either the first Sunday or Monday of the year. Days before
week 1 are numbered as 0s. In contrast to R, the as.week function
generates weeks numbered from 1 to 53. The week before week 1 takes on
the value (52 or 53) from the last week of the previous year. The
as.week functions facilitates working with multiple years and
generating epidemic curves.
MMWR week
Values for MMWR week range from 1 to 53, although most years consist
of 52 weeks. The first day of any MMWR week is Sunday. MMWR week
numbering is sequential beginning with 1 and incrementing with each
week to a maximum of 52 or 53. MMWR week #1 of an MMWR year is the
first week of the year that has at least four days in the calendar
year. For example, if January 1 occurs on a Sunday, Monday, Tuesday or
Wednesday, the calendar week that includes January 1 would be MMWR
week #1. If January 1 occurs on a Thursday, Friday, or Saturday, the
calendar week that includes January 1 would be the last MMWR week of
the previous year (#52 or #53). Because of this rule, December 29, 30,
and 31 could potentially fall into MMWR week #1 of the following MMWR
year.
EPIWEEK for STATA
Each epidemiological week begins on a Sunday and ends on Saturday. And
the first epidemiological week of year ends on the first Saturday of
January, provided that it falls at least four or more days into the
month
ISO (or business) week
An ISO week-numbering year (also called ISO year informally) has 52 or
53 full weeks. That is 364 or 371 days instead of the usual 365 or 366
days. The extra week is referred to here as a leap week, although ISO
8601 does not use this term. Weeks start with Monday. The first week
of a year is the week that contains the first Thursday of the year
Week "u" in SAS
Each epidemiological week begins on a Sunday and ends on Saturday. And
the first epidemiological week of year contains Sunday. Weeks range
from 0 to 53 but do not always count 7 days

How to add Hour with sysdate in business hour in Oracle?

Need to adding in business hours between 9 to 6 ( mean 8 hours daily and exclude Saturday and Sunday; ), now i want to add 40 hours with sysdate date.Need to display finish time,
Suppose i will assign a task on Friday 2nd of May 2014 ,10:30 AM then finish time
should be Friday 8th of May 2014 ,10:30 AM

Resources