Add formula within formula in Google Sheets [closed] - google-sheets

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 months ago.
Improve this question
I have a formula in google sheets that I am trying to work on. The data looks like
Day Date Start Time
Tuesday 1 November 8:00 am
Tuesday 1 November 8:00 am
I want the input as '#This is the-date | Tuesday, 1st November | 8:00 am (US Time)'. What I need to do is add st,th,nd in the dates which I can do using this formula
=DAY(A12)&LOOKUP(DAY(A12),{1,2,3,4,21,22,23,24,31;"st","nd","rd","th","st","nd","rd" ,"th","st"})&TEXT(A12," mmmm")
What I don't know is how to concatenate fields and add this formula in a formula as well. Right now I am doing something like this
=CONCATENATE("#This is the-date | ",A3,", ",&DAY(B3)&LOOKUP(DAY(B3),{1,2,3,4,21,22,23,24,31;”st”,”nd”,”rd”,”th”,”st”,”nd”,”rd”,”th”,”st”})&TEXT(B3,” mmmm”), " | ", (TEXT(C3,"H:MM am/pm")), " (US Time)")

use:
=INDEX(IF(A2:A="",,"#This is the-date | "&A2:A&", "&DAY(B2:B)&LOOKUP(DAY(B2:B),
{1,2,3,4,21,22,23,24,31;"st","nd","rd","th","st","nd","rd","th","st"})&
TEXT(B2:B, " mmmm | ")&
TEXT(C2:C, "H:MM am/pm")&" (US Time)"))

Related

How to convert current year month and day into minutes? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i need a variable which is contains the actual year month and day in minutes
that should be around 1061841278
var plus = calendar.dateComponents([.year, .month, .day], from: Current).minute
i wrote this but it didn't work...
Your question is tricky because it looks like your reference date is before the adoption of the Gregorian calendar. So you have to think very hard about what date you're counting from.
But let's assume you mean to count from midnight on January 1 in the year 1 on the Gregorian calendar in UTC. That's kind of a nonsense thing to say, because neither the Gregorian calendar nor UTC existed at that time. But we can extrapolate, and this will show how to approach the problem for other dates.
First, you need a calendar and a timezone to perform the calculations.
let gregorian = Calendar(identifier: .gregorian)
let utc = TimeZone(abbreviation: "UTC")!
Then, you need a reference date:
let ref = gregorian.date(from: DateComponents(timeZone: utc, year: 1, month: 1, day: 1))!
And then you can perform the calculation in minutes:
let diff = gregorian.dateComponents([.minute], from: ref, to: Date()).minute
When I did this, the answer was 1061841271, which is pretty close to your expectations.
Be very careful with creating reference dates in this era. You will want to read the Historical Dates section of the Date and Time Programming Guide to ensure you're dealing with the calendars correctly. In particular, there is no year 0, and Calendar skips 10 days in 1582 due to the Julian/Gregorian adjustment.

Formula To Calculate Accrued Quarterly Allowance Based On Employment Length

Employees get a specified amount of allowance for each quarter of the year, which accrues as the year progresses, and resets each new year. The amount they get each quarter is determined by how long they have been employed.
YEARS EMPLOYED | $ PER QUARTER
<1 | $0
>=1 | $37.5
>=3 | $66.66
>=5 | $100
Using only one reference cell (the hire date in Cell O1), I'm trying to figure out how to put a formula together which would display the sum of all quarterly amounts accrued this year to date.
The part that is giving me trouble is that when the amount per quarter changes during the year (due to the number of years employed reaching the next level), any previous quarters for the year need to remain at their previously assigned amounts, for example:
If the HIRE DATE is April 16, 2015:
QUARTER | YEARS HIRED | QUARTERLY ALLOWANCE
Q1 | 2.71 | $37.5
Q2 | 2.96 | $37.5
Q3 | 3.21 | $66.66
Q4 | 3.46 | $66.66
If TODAY'S DATE is May 21, 2018, the total allowance amount to date = $75 (Q1+Q2)
If TODAY'S DATE is Oct 7, 2018, the total allowance amount to date = $208.32 (Q1+Q2+Q3+Q4)
How can this be done with one formula, using only the hire date in Cell O1?
I think the easiest way to get the number of complete years hired is to use Datedif:
=DATEDIF(O$1,DATE(YEAR(P$1),RIGHT(A2)*3-2,1),"Y")
placed in (say) E2, where the current date is in P1 and the list of quarters starts in A2
Then a lookup to get the allowance calculated on the first day of each quarter:
=LOOKUP(E2,{0,1,3,5},{0,37.5,66.66,100})
and finally a check to see if the first day of the quarter is on or before the current date:
=P1>=DATE(YEAR(P1),MONTH(RIGHT(A2)*3-2),1)
Then you could get the total from
=SUMPRODUCT(F2:F5*G2:G5)
Or you could combine all this into one big array-type formula:
=SUMPRODUCT((P1>=DATE(YEAR(P1),{1,4,7,10},1))*LOOKUP(DATEDIF(O1,DATE(YEAR(P1),{1,4,7,10},1),"Y"),{0,1,3,5},{0,37.5,66.66,100}))

Add 1 Day to a Date [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am creating an alarm clock app for IOS. Long story short, I have configured the DatePicker to display only hours and minutes.
My problem is that When the user inputs 6:00 AM, I want it to be for the following morning, where Xcode now is assuming it is the same day.
EX: The user goes to sleep at 10 pm on a Wednesday and sets his alarm for 6:00 AM Thursday. My app is assuming the 6:00 AM is meant for Wednesday. How can I fix this?
The most reliable way to get the next occurrence of a time is nextDate(after:matching:matchingPolicy: of Calendar because it considers also daylight saving changes.
assuming datePicker is the NSDatePicker instance:
let date = datePicker.date
let calendar = Calendar.current
// get hour and minute components of the given date
let components = calendar.dateComponents([.hour, .minute], from: date)
// calculate the next occurrence of the date components from now
let nextOccurrence = calendar.nextDate(after: Date(), matching: components, matchingPolicy: .nextTime)
I like using the AFDateHelper library personally.
import AFDateHelper
let tomorrowDate = dateFromPicker.adjust(.day, offset: 1)

How to include month and year in arrayformula sumif statement

I have the following code which I'm using in my Google Spreadsheet.
=ArrayFormula(sumif(month(income!A$2:A), month(A2) , income!B$2:B))
There are two sheets, main and income.
Income sheet contains payments received in every month. (there are multiple payments in each month). So I sum up earnings in a month and display them as monthly earning in main sheet.
The problem is - since it only considers month, when we have april 2014 and april 2015, the total sum for april in main sheet counts both years.
I am trying to figure out how to use year+month in the formula. Any help?
I just figured it out using the TEXT function.
Here's what I did:
=ArrayFormula(sumif(text(income!A$2:A, "mmm yyyy"), text(A2, "mmm yyyy") , income!B$2:B))
The first value in sumif is this:
text(income!A$2:A, "mmm yyyy")
It basically fetches month and year from all rows in column A in income sheet.
The second value is:
text(A2, "mmm yyyy")
It fetches month and year from A2 cell in main sheet.
Those two are compared. And we get the result. Problem solved.

Loop over hour:minute [duplicate]

This question already has answers here:
How can i loop through a daterange with different intervals?
(5 answers)
Closed 8 years ago.
I'm with Rails 4:
I need to make a loop in a table to display time of the day as title of column, like that
8:00 | 8:30 | 9:00 .... 20:00 | 20:30 | 21:00
Do you have any idea how to define the loop?
I've try complicated things with step() but meaby I have miss a easy way using Time?
Thanks
You could use Rails DateTime like this (for n steps you want)
startdate = DateTime.new(2001,2,3)
interval = 30
formatstr = '%H:%M'
(0..n).map{|offset| startdate + (offset * interval).minutes }
.map{|date| date.strftime(formatstr)}

Resources