Date offset from beginning of year - ios

I want to know How do I find the date offset from beginning of year in iOS. I want a function which will take the date as an input and tell me the number of days passed.
For ex Jan 2 = 2nd Day of year and Feb 14 = 45th Day of Year

Related

Add multiple number of months to specific date until date in future - Google Sheets

In Google Sheets I need calculate next date in future from TODAY based on start date adding specific number of months (or multiple of them). When I will open it everytime in future it will always calculate correct date.
Example:
Today is 2021-12-01
Start date = 2021-02-07, interval = 5 months => next date should be 2021-12-07
Start date = 2021-09-07, interval = 3 months => next date should be 2021-12-07
Start date = 2021-09-07, interval = 12 months => next date should be 2022-12-07
Start date = 2021-12-07, interval = 12 months => next date should be 2021-12-07
Idealy would be to have 3 cells: start date, interval, future date.
I have no idea how to do it using one "unversal" formula.
Please help.
=DATE(YEAR(A1),(MONTH(A1)+B1),DAY(A1))
Where:
A1 = Start date
B1 = Interval
C1 = Formula (Next date)

Google sheets previous 6 months data query

so I have this query that pulls all the data from the previous month but I would like it to pull the previous 6 months
=query(Insiders!A4:L,"Select * where month(C)=month(now())-1",1)
Taking the current month as July, if you want to display results where the date in Col C is in Jan 2021 to June 2021 inclusive, then try this:
=arrayformula(query(Insiders!A4:L,"Select * where C>= date '"&text(eomonth(today(),-7)+1,"yyyy-mm-dd")&"' and C< date '"&text(eomonth(today(),-1)+1,"yyyy-mm-dd")&"' ",1))
Currently (at 10/7/2021), text(eomonth(today(),-7)+1,"yyyy-mm-dd") = 2021-01-01
text(eomonth(today(),-1)+1,"yyyy-mm-dd") = 2021-07-01
These are the two date search ranges.
You can alter the eomonth() function parameters -7 and -1 to move the months into a different period.
try:
=QUERY(Insiders!A4:L, "where month(C)+1="&MONTH(TODAY()), 1)

What is the week number of a week with a weekday(of day X) in a month of a given day X?

I'm looking for a way to get the week number of a week with a weekday(of day X) in a month of day X.
For example:- What is the week number of the week with weekday Tuesday in it of day 13? Answer - second.
Image of the April month
I know it sounds confusing so here's example 2 - If I provide a date of 24 May 2021 then I would like to know that it is the fourth Monday of the month.
Image of the May month
I would be happy with a general answer but it would be great to know if there's an efficient way to do that using dart. Thank you.
Simple math. Get the day of week. Get the day of month, subtract 1, and integer divide by 7, and add 1. Now you have "Monday" "4th one of the month".
To explain, think about it. Days numbered 1 to 7 are always the first one of those days in the month. Similarly, days numbered 8 to 14 are always the second one of those days in the month. Quick math shows that you want:
(dayOfMonth - 1) ~/ 7 + 1
and for dayOfWeek, 1 Jan 1970 was a thursday, and here's some code:
void main() {
var epoch = DateTime.utc(1970, 1, 1);
var target = DateTime.utc(2021, 5, 24); // your input goes here
var days = (target.difference(epoch)).inDays;
// epoch is thursday, so we count back to following sunday
days -= 3;
var dow = days % 7;
print(dow); // sunday = 0 ... saturday = 6
}
This prints "1" in dartpad. Monday!
Be sure to use utc, or you can get messed up on DST.

Add one month to current date

I want to add 1 month to date, but it is adding only 4 weeks.
I tried like this,
2012-05-04 + DateTimeUtilities.ONEMONTH = 2012-05-31
The result i am getting is 2012-05-31
I want to add a full month (30 days or 31, or when month is a leapyear 29 or 28).
Try converting your time to a Calendar object then increment the month field:
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(timeInMillis));
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)+1);
long newTimeInMillis = cal.getTime().getTime();
You may want to check for overflow from December to January and increment the year.
The API documentation confirms that DateTimeUtilities.ONEMONTH is four weeks, so what you got is what you should expect.

Get Week Of The Year

Delphi Xe, Win 7, System TimeZone UTC+4:0, The first day of week in system - Monday, Time is synchronised with time.windows.com
In a palette of standard components Delphi Win32 there is component MonthCalendar, at it property WeekNubers=true (display of numbers of weeks), date=now, the first day - Monday.
Shows on 19 number (today) - number of week 43.
I request number through dateutils.WeekOfTheYear(now) = returns 42.
Source (0.5 Mb) http://www.sendspace.com/file/yuz6ko
Judging by an initial code of component MonthCalendar - there like all it is true (even if not to expose the first day of week, it takes value from system parametres).
And in inquiry WeekOfTheYear it is told, that all is considered also standard ISO applied, but numbers do not coincide :(
In any way I will not understand, where one week disappears - if to look on a calendar, should be 43 and if to consider, that weeks 53 and the first concerns last year...
By the way WeekOfTheYear on 01.01.2011 too returns 52 though like should return 1...
Why distinctions and where it is correct?
Both results are correct, the difference is because the DateUtils.WeekOfTheYear function uses the ISO 8601 standard definition of a week. That is, a week is considered to start on a Monday and end on a Sunday.
Check this explanation about the Weeks Numbers in the ISO 8601 format.
If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in
week 01. If 1 January is on a Friday, Saturday or Sunday, it is in
week 52 or 53 of the previous year (there is no week 00). 28 December
is always in the last week of its year.
Also the Embarcadero online help for the DateUtils.WeekOfTheYear function says
....if the first calendar day of the year is a Friday, Saturday, or
Sunday, then for the first three, two, or one days of the calendar
year, WeekOfTheYear returns the last week of the previous year.
Similarly, if the last calendar day of the year is a Monday, Tuesday,
or Wednesday, then for the last one, two, or three days of the
calendar year, WeekOfTheYear returns 1 (the first week of the next
calendar year).
So due which the 01-01-2011 was Saturday this week is considered the week number 52 of the previous year.
And that also explains why the week number returned for today (19-10-2011) is 42 instead of 43.
First of all, I could see no difference between the week numbers in the TMonthCalendar component and those returned by DateUtils.WeekOfTheYear(). (Monday is the first day of week on my system.) Both show 42 for the current week and 52 (not 53) for the week of 2011-01-01. (It's 53 for 2010-01-01, so maybe you just mixed that up.)
Now, as to why it's 52 or 53, but not 1, well, it's according to the definition of the first week by ISO:
First week is the week with the year's first Thursday in it.
So week number 1 in 2011 starts on 2011-01-03, and the previous one belongs to the previous ISO year.
The TMonthCalendar can treat the last week of the year as the first week of the next year, WeekOfTheYear function does not do it, hence the difference.
For example according to TMonthCalendar, 1 Jan 2012 belongs to both last week of 2011 and first week of 2012; 2 Jan 2012 is the first day of the second week of 2012.
According WeekOfTheYear function, 1 Jan 2012 belongs to the last week of 2011 only; 2 Jan 2012 is the first day of the first week of 2012.
Monday is the first day of the week for me.

Resources