Calculate days excluding weekends in Sharepoint2010 - sharepoint-2010

How do I exclude weekends(sat and sun) when counting number of days between a start and end time in Sharepoint 2010 calculate column.
1.I have a calendar added to Sharepoint 2010 and there is two columns as start time and end time and now my requirement is to calculate the number of days between star time and end time excluding the weekends(sat and sun) means it will calculate working days only.
tried this
=IF(AND((WEEKDAY(EndDate,2))<(WEEKDAY(StartDate,2)),((WEEKDAY(StartDate,2))-(WEEKDAY(EndDate,2)))>1),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)-2),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)))
Also,
=(DATEDIF([StartDate],[EndDate],"d"))-INT(DATEDIF([StartDate],[EndDate],"d")/7)*2-IF((WEEKDAY([EndDate])-WEEKDAY([StartDate]))>0,2,0)+1
but not getting the correct output.

=IF(AND((WEEKDAY(EndDate,2))<(WEEKDAY(StartDate,2)),((WEEKDAY(StartDate,2))-(WEEKDAY(EndDate,2)))>1),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)-2),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)))
this should do the trick :)

Don't know why, but I ended with above -1, that is:
=IF(AND((WEEKDAY(EndDate,2))<(WEEKDAY(StartDate,2)),((WEEKDAY(StartDate,2))-(WEEKDAY(EndDate,2)))>1),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)-2),(((DATEDIF(StartDate,EndDate,"D")+1))-(FLOOR((DATEDIF(StartDate,EndDate,"D")+1)/7,1)*2)))-1
Using this way it worked for me.

Try below formula:
=DATEDIF([Start Date],[End Date],"D")-IF(WEEKDAY([End Date])=7,FLOOR((DATEDIF([Start Date],[End Date],"D")+WEEKDAY([Start Date]))/7,1)*2,FLOOR((DATEDIF([Start Date],[End Date],"D")+WEEKDAY([Start Date]))/7,1)*2+1)+IF(WEEKDAY([Start Date])=7,2,1)

This worked best for me.
ROUNDUP(([End Time]-[Start Time]),0)-IF(WEEKDAY([End Time])=7,FLOOR((DATEDIF([Start Time],[End Time],"D")+WEEKDAY([Start Time]))/7,1)*2,FLOOR((DATEDIF([Start Time],[End Time],"D")+WEEKDAY([Start Time]))/7,1)*2+1)+IF(WEEKDAY([Start Time])=7,2,1)

Formula to calculate networkdays in sp Tested and working:
=(DATEDIF([Start Date],[End Date],"D"))-INT(DATEDIF([Start Date],[End Date],"D")/7)*2-
IF(WEEKDAY([End Date])<WEEKDAY([Start Date]),2,
IF(OR(WEEKDAY([End Date])=7,WEEKDAY([Start Date])=1),1,0))+1

Related

SQL - Automatically adjust Where clause to previous month in YYYY-MM format

(This is all steps in containers within an Alteryx flow that is connecting to a Teradata source)
My SQL is incredibly rusty as it's been almost 8 years since I've needed to use it. I know this is a quite basic question. Basically I have several queries that need to be manually adjusted monthly to shift the month. in YYYY-MM format. They look like this:
Is the main one where I just adjust one backwards one month
select DB.TABLE.field1, DB.TABLE.Year_month
from DB.TABLE
where DB.TABLE.Year_month = '2023-01'
This is the secondary one where I adjust one backwards one month, and the others are same month or plus a month or more.
and A.B_MONTH in ('2022-12-01', '2023-01-01', '2023-02-01', '2023-03-01', '2023-04-01','2023-05-01')
and B.Year_month = '2023-01'
How do I adjust the where clause to always be the needed relative references?
Any help is greatly appreciated
I tried using concat but it choked for some reason.
You can try this:
select DB.TABLE.field1, DB.TABLE.Year_month
from DB.TABLE
where DB.TABLE.Year_month = DATE_FORMAT( NOW() - INTERVAL 1 MONTH, '%Y/%m')
I don't understand your second need, but you can do it similar to my response.
Just play with the NOW() - INTERVAL X.
Pretty basic stuff. ADD_MONTHS to move your month around, TO_CHAR for your desired format.
To get the previous month:
select to_char(add_months(current_date,-1), 'YYYY-MM')

SSAS (Tabular) / DAX - Calculate measure over time / Rolling distinct count

I've a question about a rolling distinct count. I'm trying to calculate the latest 30 weeks (210 days) from a specific date (eg. Specific date = 18-02-2019 distinct count from 23-07-2018).
I've found a website/blog where this is explained, https://radacad.com/datesinperiod-vs-datesbetween-dax-time-intelligence-for-power-bi. But in some weird way, my calculation is not working.
My DAX expression:
Aantal mutaties afgelopen 30 weken:=
CALCULATE(
DISTINCTCOUNT(FCT_KlantReis_Mutatie[Mutatie]);
DATESINPERIOD(
FCT_KlantReis_Mutatie[Mutatiedatum];
LASTDATE(FCT_KlantReis_Mutatie[Mutatiedatum]) ;-210;DAY)
)
But in Excel (and PowerBI) I get the following result:
The table is linked to a date dimension. My guess is that it must be posible, but how...
Thanks in advance for the help.

A way to check for specific month in specific year sql?

Out of curiosity I was playing around with SQL, and as we all know, DATEPART() and DATENAME() can be used to check for tuples with a specific day, year, or month as a condition for us to browse through records in a relation.
But I was just curious whether there is a way to check for both at the same time without using something like:
DATENAME(MONTH,Datevariable1)="February" AND
DATEPART(DAY,Datevariable2)="26"`
to find these records.
Is there a simpler way of doing it? I am asking this question just out of curiosity.
The month() function will call back a specific month. the range is 0 not a month and 1-12 in this case you wanted Feb so we check month against 2. And the day function acts the same way it will look for that day which is set to 26 in this case. Hope it Helps.
The mysql Statement
SELECT *, MONTH(dateColumn)=2 and DAY(dateColumn)=26 as 'MY_MONTH_AND_DAY' FROM yourTable;
By that you want a function that can return "26 Feb" instead of 26 alone and Feb alone?
If that the case you can use something like this in SQL Server
LEFT(CONVERT(VARCHAR(9), dateColumn, 6),6)

displaying records with a date at least one day greater then or = to today

I have a field in a table called DATEF. It displays dates as follows: 2013-11-25 08:30:00.000. The field is used to show appointment dates. What I need to show are future appointment dates from today or = to today. (Getdate) for some reason this is not working for me today. Appreciate the help. Thank you.
Try this... you're probably failing to factor in the time component. (This is for SQL Server, you'll have to find the equivalent for your respective environment)
SELECT <SOMETHING>
FROM TABLE
WHERE DATEF >= CONVERT(DATE,GETDATE())

SQL adding two columns (datetime)

I have two columns that contains datetimes and i need two add them together somehow. I've tried using sum but that didnt work. Im using sqlserver 2008.
Columns
loanPeriod = the loanperiod of the item
checkOutDate= when the item was borrowed
And Im trying to achieve this
lastreturndate = (checkoutDate + loanperiod)
select dateadd(month, loanperiod, checkoutdate) as lastreturndate
Most databases have a DATEADD() or DATEDIFF() function or similar.
Presumably, these are measured in days. So, you can do something like this:
select dateadd(day, datediff(day, 0, loanPeriod), checkoutDate)
It is odd to store the loan period as a datetime. If so, the date is going to look like some date early in the 1900s (unless the period is very long). The above converts it to days and then adds it to the check out date.