Access, Change all dates to Mondays - date

is there a quick way to nest an if (IIF?) in an UPDATE string to change all dates to the appropriate monday day of that week? So, if a date read TUESDAY 30 JULY, i would want it to be automatically updated to MONDAY 29 JULY. I figured an UPDATE TABLE, but unsure where to go from there. Thanks!

You need something similar to this:
UPDATE tablename SET fieldname = fieldname-Weekday(fieldname,2)+1
Weekday() returns a number 1..7 indicating the day of the week. By default, 1 is Sunday. The argument 2 says to starting counting from Monday, so Monday is 1 and Sunday is 7.
So, for example, if the field's date is a Monday it subtracts 1 then adds 1, remaining Monday; if it's Tuesday it subtracts 2 (0) then adds 1 = 1, Monday.

Related

How to calculate the weekend when counting a date range in Google Sheets?

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

Fetching the 15th last working day date-yyyyMMdd (excluding only weekends) in Hive

I have a table with date column (date in string format yyyyMMdd). My requirement is to design a logic to fetch data from the table where "date column value equals to the date of the 15th previous working day" (excluding only Saturdays and Sundays) without using a UDF or a shell script. For example it is 21st Feb 2020 today; the logic should produce an output: 20200203.
Assuming you actually mean the 14th previous working day based on your example, and you are ignoring holidays, it is just a date_sub function with a case statement for day of the week.
case from_unixtime(unix_timestamp(event_date,'yyyyMMdd'),'u')
when 1 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),20),'-','')
when 2 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),20),'-','')
when 3 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),20),'-','')
when 4 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),20),'-','')
when 5 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),18),'-','')
when 6 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),18),'-','')
when 7 then regexp_replace(date_sub(from_unixtime(unix_timestamp(event_dt,'yyyymmdd' )),19),'-','')
end as new_date
This assumes Sat/Sun should be treated like Monday,
If Sat/Sun should be like Friday then make then use 19, 20.
If you need to account for holidays, then you need to create a calendar table with every day, and note which days are holidays, and then it is a join to the table and a some more logic that could be figured out if this is the case.

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+

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.

How to show date from last monday to sunday?

I am trying to create an Analytics report and I want to set the date range from Monday to Sunday.
I am setting the Start date to: =today()-7 and the End day to =today()-1, but this shows the last 7 days everytime I run the report (say I run it on wednesday, it will show data from wednesday to tuesday).
How can I set the date range so it shows it from last Monday to Sunday?
Short answer
Use WEEKDAY
Explanation
WEEKDAY returns the day of the week.
To get the Monday's date, use this value to subtract it from today's date.
To get the Sunday's date, add 6 to the monday date.
Example
Today =today() 11/14/2016
Weekday =WEEKDAY(B1,3) 0
Start =B1-B2 11/14/2016
End =B3+6 11/20/2016

Converting month to date format in access

I have an access column which has values like May, May-June, November, January-February etc.
Requirement is that
1) If only one month is there, I should create a transformation with a date column pointing to the last date of that month and the year would be the current year.
Eg May would be 5/30/2015, January would be 1/31/2015
2) If it is having two months, then second month must be taken and the same logic as in Point 1 should be implemented.
Eg May-June would be 6/31/2015, January-February would be 2/28/2015.
My first preference would be without using VBA code.
Please help.
You can use a one-liner in a function:
Public Function GetDateFromMonth(ByVal Months As String) As Date
Dim Ultimo As Date
Ultimo = DateAdd("d", -1, DateAdd("m", 1 + UBound(Split(Months, "-")), CDate(Split(Months, "-")(0) & "/1")))
GetDateFromMonth = Ultimo
End Function
Split the string on the "-", use the second month, add one to that month to get the next month, then take the first day of that month and subtract one from it. For example Jan-Feb : build 3/1/2015 and then subtract 1 day to get the last day of Feb.
Make a table that holds a list of Months:
MonthName MonthNumber
January 1
February 2
March 3
April 4
May 5
June 6
July 7
August 8
September 9
October 10
November 11
December 12
Create this query:
SELECT InputData.Months, DateSerial(Year(Date()),[MonthNumber]+1,0) AS ReqdDate
FROM InputData, Months
WHERE (((IIf(InStr([Months],'-')=0,[Months],Mid([Months],InStr([Months],'-')+1)))=[MonthName]));
That's it. Output looks like this:
Months ReqdDate
May 31/05/2015
May-June 30/06/2015
November 30/11/2015
January-February 28/02/2015
March 31/03/2015
April-September 30/09/2015
Sorry about formatting - noob. I'm in Eu so my dates look odd to you, but you get the idea; you can make them US dates in a moment I'm sure. You can use the bits of this you need in your code in two secs.
If you don't like the lookup table for month number, I'm sure you can use some format function to turn the month name into a month number.