I have sets of date/time range values, each set came from different column ("FROM" and "TO")
examples:
FROM: June 6, 2016 7:00 AM; TO: June 6, 2016 5:00 PM
FROM: June 6, 2016 8:00 PM; TO: June 7, 2016 6:00 AM
I want to get how many minutes of each set falls to 3:00 PM - 2:00 AM (next day) or "OFF PEAK HOURS", like this
for the example above, I want to get the number of minutes between 3PM - 2AM next day.
on the first row, from 7AM-5PM, two hours is included to my 3PM-2AM range criteria, which is 3PM-5PM (2 hours) . Thats why I got 120 mins.
on the second row, from 8PM-6AM next day, two hours is included to my 3PM-2AM range criteria, which is 8PM-2AM (6 hours). Thats why I got 360 mins.
see this graph for reference:
I want to count the number of minutes falls during "OFF PEAK HOURS"-shaded in orange/tan.
Is it doable in expression?
Thank you in advance.
Please note that I am using fetchXML for the query.
Supposing the table you put in the question is wrong and it is only an example, I think you can get the spent minutes between two dates by using this expression:
=DateDiff(DateInterval.Minute,
Fields!From.Value,
Fields!To.Value
)
Example:
=DateDiff(DateInterval.Minute,
CDATE("2016-06-06 07:00:00 AM"),
CDATE("2016-06-06 05:00:00 PM")
)
The above example returns 600. 10 hours by 60 minutes. DateDiff function returns the specified date/time interval of time between two specified dates.
Let me know if this helps.
Related
If I run this query on my database
SELECT EXTRACT('epoch' FROM age('2021-01-01'::date, '2019-12-01'::date))
The result is 34149600.
But then if I try with 2019-12-02 (one day more)
SELECT EXTRACT('epoch' FROM age('2021-01-01'::date, '2019-12-02'::date))
The result is exactly the same 34149600!
As if the seconds passed from 02 december 2019 to 01 january 2021 are the same as the seconds passed from 01 december 2019 to 01 january 2021.
Why is this? I've already tried the above code with timezones on 00:00:00+00 timezone for all dates (for 1st january 2021, 1st december 2019 and 2nd december 2021), and it gives the same result
Obviously, I would have expected the epoch to be different, around 3600*24 of difference (seconds in a day).
The similar results come from the age() function which returns an interval with years, months, days. In such an interval, 1 month = 30 days, so their conversions in seconds are similar.
You will get the expected result with
SELECT extract(epoch from ('2021-01-01'::timestamp - '2019-12-01'::timestamp)) => 34300800.000000
SELECT extract(epoch from ('2021-01-01'::timestamp - '2019-12-02'::timestamp)) => 34214400.000000
I have the below columns
StartDate EndDate CountDay
01 May 20 05 May 20 ?
As you see, 01 May is Friday, so from 01-05 May if we count all days including weekend it will be 4 days.
What I want is on column "CountDay" it only counts the Workdays, not the weekend.
SO the expected result would be 2.
Anyone know how to do it using a formula in Google Sheets?
Do you consider Fridays as part of the weekend?
If yes, then you could also try the following formula:
=NETWORKDAYS.INTL(A10, B10,"0000111")
If not, please use this formula:
=NETWORKDAYS.INTL(A10, B10)
How the formulas work.
By using the function NETWORKDAYS.INTL we can "adjust" the weekend (non-working weekdays) to our liking.
In this case we account Fridays as our non-working weekdays by using as the 3rd parameter 0000111 instead of the default 0000011 where every 0 represents a working weekday and every 1 a non-working weekday.
(Very useful for people working part-time)
Someone who has part-time work on only Mondays, Wednesdays and Fridays and wants to calculate the working days Friday, 1 May 2020 - Tuesday, 30 June 2020 could adjust the formula to:
=NETWORKDAYS.INTL(A10, B10,"0101011")
As explained on the official Google help page for NETWORKDAYS.INTL
weekend – [ OPTIONAL – 1 by default ] – A number or string representing which days of the week are considered weekends.
String method: Weekends can be specified using seven 0s and 1s, where the first number in the set represents Monday and the last number is for Sunday. A zero means that the day is a work day, a 1 means that the day is a weekend. For example, “0000011” would mean Saturday and Sunday are weekends.
Number method: Instead of using the string method above, a single number can be used. 1 = Saturday/Sunday are weekends, 2 = Sunday/Monday and this pattern repeats until 7 = Friday/Saturday. 11 = Sunday is the only weekend day, 12 = Monday is the only weekend day and this pattern repeats until 17 = Saturday is the only weekend day.
I just found how to do it:
=if(weeknum(A10)<weeknum(B10),B10-A10-2*(weeknum(B10)-weeknum(A10)),B10-A10)
something like that
Creating a function that takes a start and end date and counts how many Sundays between those dates fell on the 1st of the month on kdb+, how would I do this?
The function needs to show how many times this has happened since 1950
Let's define a function which returns a weekday of its argument (of type date) first.
The underlying value of a date is the count of days from 1/1/2000 and we know that 1/1/2000 was Saturday. The next day was obviously Sunday, then Monday etc. and every 7th, 14th, 21st, etc. day after and before Jan 1, 2000 was Saturday too. So if we take a date modulo 7 we'll get a weekday number where 0 is Saturday, 1 is Sunday, etc. which leads us to the following definition.
weekday:{ `sat`sun`mon`tue`wed`thu`fri x mod 7 }
Now we can create a function that answers the original question:
sundaysThe1st:{[start;end]sum `sun=weekday dates where 1=`dd$dates:start+til 1+end-start }
start+til 1+end-start generates a list of dates between start and end, dates where 1=`dd$dates returns only the first days of the months and `sun=weekday dates returns 1b if the 1st day of the month is Sunday and 0b otherwise. sum is effectively the number of 1's which is exactly what we need.
Hope this helps.
I am trying to get week numbers ( resetting at 1 for each month) as per ISO format for each month in 2019.For example I am interested in getting
All dates in July 2019: week 1 to 4,
All dates in Aug 2019 : week 1 to 4 and so on.
I first created the calculated field (Week_Number_ISO) to get the overall week number in year 2019.I used the following formula;
DATEPART('iso-week',[ Date]) which works as intended.
To get the monthly week number I used the following formula
INT((DATEPART('day',[Created Date])-DATEPART('iso-weekday',[Created Date])+7)/7)+1.
(Idea was to calculate the date of the first day of each week & then divide by 7 and take the integer part)
As per the ISO format, shouldn't July 29 to 31st be a part of week 4 for July?But the formula is showing it as week 5 for July 2019.I feel I am missing something in the formula or am missing something about ISO week number resetting at 1 for each month.
Can someone help me?
Here is an example of the dates in July 2019 and the associated week numbers.
Why would July 28th-July 31st 2019 be considered week 4?
I am trying to develop a scheduling application that needs to represent rules such as "this event occurs on the 2nd and 4th Wednesdays of the month" or "this event happens on odd-numbered Saturdays of the month (i.e. the 1st, 3rd, and 5th Saturday).
To that end, I need to write a function in T-SQL that takes a Date input and returns an integer representing which occurrence-in-month of the dayname falls on that date.
For example, if I send the function 2012 DEC 21, it would return 3, because December 21, 2012 falls on the 3rd Friday of that month. Given 2012 DEC 29, it would return 5, since December 29, 2012 falls on the 5th Saturday of that month.
I'd like to do this without recourse to a prepopulated calendar table. I might want to use the function to work with historical dates, e.g. to compute which Wednesday of the month July 16, 1958 was.
Try this:
SELECT ((DATEPART(d, #input) - 1) / 7) + 1
We don't care about the actual day of the week, just the number of days past the first of the month (which is the day value - 1). Then an integer divide by 7 to get the number of weeks past the first of the month, and finally + 1 to have it start at 1 instead of 0.