How to check whether day satisfies the recurrence condition using google sheet formula - date

I have a Google sheet where it has startdate, frequency, count. I need to check whether the todays date is satisfying the recurrence and display TRUE if today() is satisfied and false if not satisfied.
This will help me determine each time, the sheet is opened I can find out from TODAY() date is satisifed or not?
https://docs.google.com/spreadsheets/d/142od5eUib5nHmdi4mnENuPbh-Yn485NzUSt90p84QE0/edit?usp=sharing

Like #Scott Craner said, just compare the result of the formula from the previous question with TODAY():
={
"Today is the day?";
ARRAYFORMULA(
IF(
A2:A = "",
,
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
) = TODAY()
)
)
}

Related

Dynamic date pivot using CTE

I have a CTE which i get after lot of calculations, So the final CTE contains three columns
namely, "Name", "Values" & "Dates".
I have searched google and in all PIVOT the dates are hardcoded and i don't wan this dates to be hardcoded as the dates will be dynamically changed.
Any suggestions how i can get this result with a CTE and with dynamic dates pivot?
Version PostgreSQL 11
Sample input
Value. Name Date
"1" "Coenzym Q10" "2020-06-29"
"1" "Coenzym Q10" "2020-06-30"
"4" "Coenzym Q10" "2020-07-01"
"1" "Coenzym Q10" "2020-07-02"
"5" "Coenzym Q10" "2020-07-03"
"1" "Coenzym Q10" "2020-07-04"
"2" "D12" "2020-07-01"
"4" "D12" "2020-07-04"
Desired Output
"Name" "2020-07-04". "2020-07-03" "2020-07-02" "2020-07-01" "2020-06-30". "2020-06-29"
"Coenzym Q10". "4" "5" "1" "1" "1" "1"
"D12" "4" "2"
If you don't insist of having the dates as the column name (header), you could do something like this:
select "Name",
max("Value") filter (where date = current_date) as "Today",
max("Value") filter (where date = current_date - 1) as "Today -1",
max("Value") filter (where date = current_date - 2) as "Today -2",
max("Value") filter (where date = current_date - 3) as "Today -3",
max("Value") filter (where date = current_date - 4) as "Today -4",
max("Value") filter (where date = current_date - 5) as "Today -5",
max("Value") filter (where date = current_date - 6) as "Today -6",
max("Value") filter (where date = current_date - 7) as "Today -7"
from the_table
group by "Name"
order by "Name;

Is there a formula for upcoming date using formula in Google sheet based on condition?

I have a google sheet where I need to get the next upcoming date based on the start date set in column A
Any pointers are greatly appreciated? I am unable exhibit the efforts as I am completely new to this sort of recurrence using Google sheets
https://docs.google.com/spreadsheets/d/1g_UNg4MjDy3gFufpjZtMRkbBz80K3scQdZOaiAnZi7I/edit#gid=0
This behavior (the next date from today including today) could be implemented manually by this formula:
={
"Next date from today";
ARRAYFORMULA(
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
)
)
}
For additional options (like "every 2nd monday of the month" and others) additional options should be implemented in that IFS part.
If you are interested in a trivial case where the next date from the start date (column F:F on the screenshot) is needed, then the formula would be much simpler:
={
"Next date";
ARRAYFORMULA(
IFS(
B2:B = "Daily",
A2:A + C2:C,
B2:B = "Weekly",
A2:A + 7 * C2:C,
B2:B = "Monthly",
EDATE(A2:A, C2:C),
True,
""
)
)
}
Again, for additional options you'll need to add corresponding part to the IFS.
You could use IFS to check Frequency, and:
If Daily, add Count value to start date.
If Weekly, add Count value multiplied by 7.
If Monthly, since not all months have the same duration, retrieve the YEAR, MONTH and DAY indexes, add Count to the MONTH index, and set a new DATE, EDIT: or as suggested by kishkin, use EDATE.
It could be something like this:
=ARRAYFORMULA(IFNA(IFS(
B2:B = "Daily", A2:A + C2:C,
B2:B = "Weekly", A2:A + 7 * C2:C,
B2:B = "Monthly", EDATE(A2:A,C2:C)
)))

Daily interest calculator that's supposed to credit monthly given various user inputs

I'm new to programming and have been working on something to learn Python for the last few days. I'm trying to create a program that calculates daily interest and credits interest monthly given user generated inputs.
The good: The program can add deposits to the initial balance every 14 days as I wanted. The program is able to determine whether an input is a leap year or not. The program is able to determine the daily interest.
The bad: I haven't been able to figure out how to get the program to sum the calculated daily interests for a given month then add it to the beginning balance of the next month.
import datetime
from datetime import date
from datetime import timedelta
import calendar
from decimal import Decimal
def gupta():
print("Enter a start date in YYYY-MM-DD format")
date_entry = input() #records account's start date as string
year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
date1 = datetime.date(year, month, day) #records account's start date as datetime.date (module?)
print("Enter an end date in YYYY-MM-DD format")
date_entry = input() #records account's end date as string
year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
date2 = datetime.date(year, month, day) #records account's end date as datetime.date (module?)
print("The starting date is " + str(date1) + " and the ending date is " + str(date2))
print("Enter your initial balance")
initial_balance = Decimal(input()) #requests initial balance (assumes this is amount to be deposited every 14 days)
print("Enter your interest rate (as a decimal)")
interest_rate = Decimal(input()) #records interest rate as a decimal
date1 = date1.toordinal() #changes date1 to ordinal
date2 = date2.toordinal() #changes date2 to ordinal
list_interest = []
for current_date in range(date1, date2 + 1): #cycles through date1 and date2 using a step/iteration of 1
date_spread = current_date - date1
new = current_date + 1
print(date.fromordinal(current_date).strftime('%Y-%m-%d'))
print(list_interest)
if date_spread != 14: #checks to see whether additional deposit is going to be made
current_date = date.fromordinal(current_date)
new = date.fromordinal(new)
current_date_y = str(current_date.strftime("%Y"))
new_m = str(new.strftime("%m"))
current_date_m = str(current_date.strftime("%m"))
current_balance = initial_balance + 0
print(current_balance)
if calendar.isleap(int(current_date_y)):
daily_interest = round(current_balance * (interest_rate / 366), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
else:
daily_interest = round(current_balance * (interest_rate / 365), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
current_date = date.toordinal(current_date)
elif date_spread == 14: #checks to see whether additional deposit is going to be made
current_date = date.fromordinal(current_date)
new = date.fromordinal(new)
current_date_y = str(current_date.strftime("%Y"))
new_m = str(new.strftime("%m"))
current_date_m = str(current_date.strftime("%m"))
current_balance = initial_balance + 150
initial_balance = current_balance
print(current_balance)
if calendar.isleap(int(current_date_y)):
daily_interest = round(current_balance * (interest_rate / 366), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
else:
daily_interest = round(current_balance * (interest_rate / 365), 2)
print(daily_interest)
if current_date_m == new_m:
list_interest.append(daily_interest)
print(list_interest)
current_date = date.toordinal(current_date)
new = date.toordinal(new)
date1 = current_date
list_interest = []
#print(current_balance)

I need to add one day to my date in my code, tried DateAdd

Ok so my code works fine, however I need it to add one day to the OrderDate , while keeping it in the same format yyyy-mm-dd any help is greatly appreciated!
<%
inDate = oRS("ordDate")
' get each date component
thisMonth = datepart("M",inDate)
thisDay = datepart("D",inDate)
thisYear = datepart("yyyy",inDate)
' check for the length of the month and day components
if len(thisMonth) < 2 then thisMonth = "0" & thisMonth
if len(thisDay) < 2 then thisDay = "0" & thisDay
' Create the date in your format you posted above
OrderDate = thisYear & "-" & thisMonth & "-" & thisDay
%>
Using your code as an example just use DateAdd() to increment the day by 1 calendar day;
<%
inDate = oRS("ordDate")
'Add one day
inDate = DateAdd("d", 1, inDate)
' get each date component
thisMonth = datepart("M",inDate)
thisDay = datepart("D",inDate)
thisYear = datepart("yyyy",inDate)
' check for the length of the month and day components
if len(thisMonth) < 2 then thisMonth = "0" & thisMonth
if len(thisDay) < 2 then thisDay = "0" & thisDay
' Create the date in your format you posted above
OrderDate = thisYear & "-" & thisMonth & "-" & thisDay
%>
For more information of working with dates see Classic ASP - Format current date and time.
try this:
dim sOrderDate
sOrderDate=cInt(thisDay)+1
if len(thisDay) < 2 then thisDay = "0" & thisDay
if len(sOrderDate) < 2 then sOrderDate = "0" & sOrderDate
OrderDate = thisYear & "-" & thisMonth & "-" & sOrderDate
this way you preserve original date(thisDay) for manipulation and order date became tomorrow (or whatever) date.

Using expression in pick function

I have tried Num((today()-I_TRAN_DATE)/90 + 1,0) individually and it will return integer, but it seems not working when I try to combined it with pick function. I know it's not finished but should at least return result for 1-3
pick(
Num((today()-I_TRAN_DATE)/90 + 1,0)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year'
)
This looks like an issue with passing the number from the expression to the pick function. When using the num function, this does not change the underlying value - including a few more brackets and a round function resolves the issue as per the below script which generates a list of dates and then applies the pick function at the end.
Let varMinDate = Num(31350); //30/10/1985
Let varMaxDate = Num(42400); //31/01/2016
TempCalendar:
LOAD
$(varMinDate) + Iterno()-1 As Num,
Date($(varMinDate) + IterNo() - 1) as TempDate
AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate);
TestCalendar:
Load
TempDate AS I_TRAN_DATE,
week(TempDate) As Week,
Year(TempDate) As Year,
Month(TempDate) As PeriodMonth,
Day(TempDate) As Day,
if(Year2Date(TempDate),1,0) as CurYTDFlag,
if(Year2Date(TempDate,-1),1,0) as LastYTDFlag,
inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12,
date(monthstart(TempDate), 'MMM-YYYY') as MonthYear,
Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear,
WeekDay(TempDate) as WeekDay,
if(TempDate>=MonthStart(AddMonths(Today(),-12)) and(TempDate<=MonthStart(Today())),1,0) as Rolling12Month
,'Q' & Ceil (Month(TempDate)/3) as Quarter
,Year(TempDate)&'-Q' & Ceil (Month(TempDate)/3) as YearQuarter
,if(Year(TempDate)=(Year(Today())-1),1,0) as LastYear
, if(MonthStart(TempDate)=MonthStart(Today()),null(),'Exclude Current Period') As ExcludeCurrentPeriod
Resident TempCalendar
Order By TempDate ASC;
Drop Table TempCalendar;
Let varMinDate = null();
Let varMaxDate = null();
PeriodTable:
Load
Pick(round((num((((today()-I_TRAN_DATE)/90) + 1),0)),1)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year') as Period
,I_TRAN_DATE
Resident TestCalendar;