Exclude weekends [duplicate] - sql

This question already has answers here:
create custom function for date difference excluding weekends and holidays in oracle sql
(1 answer)
Oracle: Days between two date and Exclude weekdays how to handle negative numbers
(2 answers)
Closed 4 years ago.
I am trying to calculate the days between two different dates. If d1 is on saturday or sunday it should not take calculate those days. d2 is the system date.
the formula i have is
(ROUND((d2-d1)-DECODE(SIGN(TO_CHAR(d2,'D')-
TO_CHAR(d1,'D')),-1,2,0)+DECODE(TO_CHAR(d1,'D'),7,1,0)-
DECODE(TO_CHAR(d2,'D'),7,1,0),2)) AS "DAYS",
this would give me 1 days from friday to sunday which is correct, but 7 days from sunday to last sunday instead of 5. anyway i can improve on this formula, or is there a simpler one i can use?

Related

Previous Workday in Where Clause [duplicate]

This question already has answers here:
How to get Previous business day in a week with that of current Business Day using sql server
(8 answers)
Select the previous business day by using SQL
(3 answers)
Closed 3 months ago.
How do I obtain the previous working date in a where clause
without doing the following and changing this manually
WHERE date = GETDATE()-1
The date column is datetime but I just need the date too.

How to get the next business day if the current date is holiday in oracle? [duplicate]

This question already has answers here:
sql oracle ignore holidays
(2 answers)
How to get the previous working day from Oracle?
(4 answers)
Determine holidays in Oracle
(3 answers)
Closed last year.
I Need to find out the next business in oracle if the todays date is holiday. There are two different scenarios, need help in writing the logic for these scenarios at once.
If the todays date is 1/17/2022, since it is holiday(Martin Luther King Day) i want to show the date as 1/18/2022 in the output which is nothing but next business day.
If the todays date is 05/31/2021, since it is holiday(Memorial Day), at the time next business falls into next month 01/06/2021. Since it is falling into next month, i want to show the previous business day of holiday 5/28/2021 in the output.

Number of Days in a month HIVE [duplicate]

This question already has answers here:
Find last day of a month in Hive
(6 answers)
Closed 1 year ago.
Can someone let me know a simple way to get # of days in a month in HIVE SQL based on current_date.
e.g. 2021-02-16 = 28 days, 2021-06-30 = 30 days etc
Use
day(last_day(current_date))
last_day(date) returns last day date, day(date) returns day part of the date, int
See manual here: Language Manual - Date Functions

How to calculate the Week number Starts from Saturday instead of Sunday in SQL [duplicate]

This question already has answers here:
How to set monday as first day of week in SQL Server
(4 answers)
Closed 2 years ago.
I need to add a column to show the week number of the year in my procedure.
By default the SQL Server considers the week starts as Sunday and shows the week number.
But I need to calculate the week number starts from Saturday.
Code:
select datepart(week,'11-july-2020')
Output I get:
28
Output I need:
29
It should start considering from the week starts as Saturday and ends on Friday.
You can use DATEFIRST:
SET DATEFIRST 6;
select datepart(week,'11-july-2020');
It allows you to set the first day of the week to a number from 1 through 7, where 1 is Monday and 7 is Sunday.

how to find the weekend dates from given list of dates [duplicate]

This question already has answers here:
Get day of week in SQL Server 2005/2008
(11 answers)
Closed 8 years ago.
I have a list of dates and other columns in which have to find the weekend dates among them and the the weekend dates should be there in the list of given dates
Output should be some thing like this...
Any help is appricated thanks.
use datepart (dw,..
to filter data needed