Google Sheets | Return last Friday's date on Sat to Wed apart from Thu and Fri - date

I'm a bit rubbish on Google Sheets formulas... would anyone be so kind to tell me how to achieve this ?
I'd like to have a cell that returns the last Friday's date on Sat to Wed, and instead the current date for Thursdays and Fridays.
Is it possible ?
e.g. this coming days:
Sat to Wed returns Friday 12th of March
Thu 18th returns Thu 18th
Fri 19th return Fri 19th
... and so on.
Thanks!

There are many ways to accomplish this, but try this:
=IF((WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{7,1; 1,2; 2,3; 3,4; 4,5},2,FALSE))
This formula is based on the us default numbers for weekdays, where Sunday = 1. If this formula produces unexpected results, your locale may be one where Monday = 1. In this case, you'll need to adjust as follows:
=IF((WEEKDAY(TODAY())=4)+(WEEKDAY(TODAY())=5),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{6,1; 7,2; 1,3; 2,4; 3,5},2,FALSE))
Other things to keep in mind:
The + in (WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6) means OR (where * would mean AND).
The VLOOKUP is looking up the weekday of TODAY() within a simple virtual array, which is formed between the curly brackets and which instructs how many days to subtract from TODAY() given the current weekday in order to arrive at the previous Friday.

Related

Month Start Date through DAX formula

I have dates in data from
02 Aug 2018
03 Aug 2018
04 Aug 2018
.
.
.
.
30 Aug 2018..
Now i want start of the month date through Dax formula which is 01/08/2018. But in data date is 02/08/2018 which i dont want
i tried below formula
Start_Monthdate = STARTOFMONTH(EStart_Date[Date])
through above formula i get 02 Aug 2018 which i dont want
In DAX, what you can do is use the EOMONTH function.
https://dax.guide/eomonth/
Column Name = EOMONTH(table[date], -1) + 1
So the above DAX is finding the end of the previous month, then adding 1 day to it.
For the date 2/4/2020, EOMONTH gets the date 31/3/2020, then adds one day to get 1/4/2020
Time intelligence only works reliably if you use it on a calendar table that has all the dates in the year you're working with. Since your date column is missing the first day of the month, STARTOFMONTH returns the first one that you do have.
Without creating a proper calendar table, you either use EOMONTH as #Jonee mentioned or try this:
DATE ( YEAR ( EStart_Date[Date] ), MONTH ( EStart_Date[Date] ), 1 )

How can I write an ICS file for the Friday before the first Saturday of the month?

I've seen How can an ICS file be written for a recurring event? but I've got a rather complex recurrence and can't figure out a rule after looking at the syntax of RRULEs.
I want an event that happens on the Friday preceding the first Saturday of each month. This Friday-before-the-first-Saturday may of course be in the previous month. I assume that if I can get this to work, similar (but not identical) events for Friday-before-the-second-Saturday, and -third- and -fourth-, with Friday before 5th Saturdays undefined.
Obviously I'd have RRULE:FREQ=MONTHLY;BYDAY=FR; but if I try to follow some of the examples using BYMONTHDAY I run into trouble: 28 would be a valid Friday-before-a-first-Saturday in February, but in any other month, Friday 28th would be the Friday before a 5th Saturday. Similarly for 29 (in a leap year), 30 and 31.
The goal is to include this in a Google Calendar, which I know supports display of ICS RRULEs it can't edit. So, assuming it's possible, how can I create an RRULE for this event? I've considered a separate event and accompanying rule for each month length. 31: Jan, Mar, May, Jul, Aug, Oct, Dec and 30: Apr, Jun, Sep, Nov are OK, but leap years are still an issue: 28 Feb could be a Friday before a first Saturday or a 5th Saturday (e.g. 2020 so one of my first two cases fails).
You're on the right track with having to use BYDAY=FR, AND since you can do negative BYMONTHDAY, the following should do the trick:
RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=-1,1,2,3,4,5,6

UNIX previous month and year with format YYYYMM

I need to assign a variable with the value in the format YYYYMM e.g for today run the previous month values should be generated as
Var1 = 201607
Is there any in build method available? Could you share the steps to generate this?
The trick in these cases is to subtract one month from the day 15 of the current month:
$ date --date="$(date +%Y-%m-15) - 1 month"
Fri Jul 15 00:00:00 CEST 2016
Then it is just a matter of using the proper format:
$ date --date="$(date +%Y-%m-15) - 1 month" "+%Y%m"
201607
To store the value in a var, just use the common var=$(command) syntax.
From GNU Coreutils → 28.7 Relative items in date strings:
The fuzz in units can cause problems with relative items. For example,
‘2003-07-31 -1 month’ might evaluate to 2003-07-01, because 2003-06-31
is an invalid date. To determine the previous month more reliably, you
can ask for the month before the 15th of the current month. For
example:
$ date -R
Thu, 31 Jul 2003 13:02:39 -0700
$ date --date='-1 month' +'Last month was %B?'
Last month was July?
$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
Last month was June!
Also, take care when manipulating dates around clock changes such as
daylight saving leaps. In a few cases these have added or subtracted
as much as 24 hours from the clock, so it is often wise to adopt
universal time by setting the TZ environment variable to ‘UTC0’ before
embarking on calendrical calculations.

UNIX Timestamp or something else?

I have a field containing what should be a UNIX time stamp. As an example one value is 1408675380
Now when I do various online conversions, it shows the right day (22nd August) but shows the incorrect time. It should be around 21:00 or so but instead shows 02:43:00 GMT
Likewise, 1408676520 shows the correct day (22nd August) but instead of showing a time of around 22:00/23:00 it shows 03:02:00 GMT
I have no control over the data at all - just wondering if there's something obvious I'm missing?
1408849260 - Sunday, August 24th 2014, 03:01:00 (GMT) - Correct day, around 18 hours too early
1408850640 - Sunday, August 24th 2014, 03:24:00 (GMT) - Correct day, around 18 hours too early
Thanks,
JJ
Is your data in some other timezone than GMT ? something like GMT-5 (america west cost maybe ?)

How to subtract two dates in Oracle and extract the year part from the difference?

My typical requirement is that I want to subtract two Dates cast as timestamp. The Minuend (First parameter) is the current date and the Subtrahend(second parameter) is stored separately as DD, MM and YYYY in three columns. The final output should be a discrete year as number. I am playing with something like :
SELECT (TO_DATE('05-DEC-2013') -
CASE LENGTH(CAND_DOB_DD)
WHEN 1 THEN
CAST(TO_DATE('0'||CAND_DOB_DD||'-'||CAND_DOB_MM||'- '||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP)
ELSE
CAST(TO_DATE(CAND_DOB_DD||'-'||CAND_DOB_MM||'-'||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP) / 365 END YEAR
FROM CANDIDATE
The Year part as Integer will be used for a very sensitive calculation. Please suggest if the above piece of SCRIPT will yield the desired result. Thanks in advance.
For most purposes you could just use the Months_Between() function to determine the number of months between two dates, and then divide by 12 etc.. Note that the number of months is an integer when comparing two dates that have the same day of the month or are both the last day of the month.
This is tricky when it comes to leap years.
Do you count 28th Feb 2015 to 28th Feb 2016 as exactly one year, when 28th Feb 2015 to 29th Feb 2016 is one day longer but plainly is a year?
What about 29th Feb 2016 to 28th Feb 2017, or 28th Feb 2016 to 28th Feb 2017?
Think carefully about these boundary cases, but Months_Between() is likely to be your best choice.