How to exclude weekend (Sunday only) to DATEDIFF in Tableau? - data-visualization

So my current formula is this: DATEDIFF('day', MIN([Date]),MAX([Date])).
How do I exclude sundays? and holidays.

Related

Get week start from week number and year in PostgreSQL

Is there a way to get the true week start (not the first day of the month) based on year and week number in PostgreSQL?
TO_DATE(CONCAT(year,weeknumber), 'yyyyww')
is not producing the right result.

Need help aggregating custom months into a snapshot field

I am working with a dataset that has a continues date field and I want to aggregate it at a monthly level where the month ends on the 15th day of the month. So each snapshot date would go from the 15th of the month to the 14th of the following month.
Example: Snapshot Date = 7/15/2021 would correspond with the date range of 6/15/2021 through 7/14/2021.
Is there an easy way to do this for all months in the table using SQL Server.
Just subtract 14 days and convert to a year/month format. One trick is to move everything to the last day of the month:
select eomonth(dateadd(day, -14, datecol)), count(*)
from t
group by eomonth(dateadd(day, -14, datecol));

SQL calculate number of days in month excluding weekends and holidays days

I have approximately the same table (excluding count column). I want to calculate the number of working days (Mon-Fri) and exclude public holidays.
I tried to try the following query
SELECT count(distinct(date)) from MYDB where dummy <> 1
However, it gives the only total number of days including weekends. Additionally, if use this command it counts distinct dates, however, my dates do not show a full month, so another logic should've used. Could you help to figure out which code is better to use?
there should be a function in Vertica that extracts weekday from date, so to exclude weekends you'll need to add another condition like
extract(dow from date) not in (6,0)
(6 is Sat, 0 is Sun in this case)

Postgresql extract week

Why when I run
select (EXTRACT(WEEK FROM current_date)::int )
The output is 6 - why?
Today is 2016-02-14 which is the 8th week since the start of this year.
Am I getting this result wrong?
I'm looking for a function which I give it date and it tells me what week of the year this date is.
The documentation is pretty clear on the calculation:
week
The number of the ISO 8601 week-numbering week of the year. By
definition, ISO weeks start on Mondays and the first week of a year
contains January 4 of that year. In other words, the first Thursday of
a year is in week 1 of that year.
In the ISO week-numbering system, it is possible for early-January
dates to be part of the 52nd or 53rd week of the previous year, and
for late-December dates to be part of the first week of the next year.
For example, 2005-01-01 is part of the 53rd week of year 2004, and
2006-01-01 is part of the 52nd week of year 2005, while 2012-12-31 is
part of the first week of 2013. It's recommended to use the isoyear
field together with week to get consistent results.
Weeks start on a Monday, so Sunday is the end of a week (and "today" is Sunday where I am and in most of the world at this particular time). Also, the first week depends on the when the year starts.

Skip weekends Business day tasks NetSuite

Using NetSuite, I am trying to automate the creation of monthly tasks. These tasks will fall on the last day of the month, a day before, and 1,2,3,4,5 days after the last day of the month. But, the tasks can't be due on a weekend, only business days. So if the day falls on a sat or sun the dates have to move up. How can I use my custom record to calculate the next months task dates skipping weekends? Here is a screenshot of the record - see that 10/4 and 10/5 fall on saturday and sunday, how can I have it skip sat and sunday? I used the sql function option to generate the dates and days of the week.
I tested the following formula. Replace custbody_date with your field name. This formula should be set in your 'next month' column.
CASE WHEN INSTR(to_char({custbody_date}, 'DAY'),'SATURDAY') != 0
THEN {custbody_date}+2
WHEN INSTR(to_char({custbody_date}, 'DAY'),'SUNDAY') != 0
THEN {custbody_date}+1 ELSE {custbody_date}
END
This should also give you an idea to set the value for 'Next Month Day' (skipping saturday and sunday).