I know there are 365 days, but I wanted a formula that accounts for leap years.
There doesn't seem to be anything out there even remotely related to this question, which is extremely surprising to me, so I just thought I'd ask here.
let's agree that the first day of the year is always 1 of January and the last day is 31 of December
therefore to calculate number of days in given (current) year would be:
=DAYS(DATE(YEAR(TODAY()), 12, 31), DATE(YEAR(TODAY()), 1, 1))+1
or alternative:
=DATEDIF(DATE(YEAR(TODAY()), 1, 1), DATE(YEAR(TODAY()), 12, 31), "D")+1
This should also work:
=ARRAYFORMULA(SUM(EOMONTH(TODAY(),{0,12}-MONTH(TODAY()))*{-1,1}))
Related
I'm attempting to create a work schedule for contracted work, based on a rotating roster.
I have been able to make the SEQUENCE formula to list days between two dates, stepped by the number of weeks the rotation is set to, but I would like it to only list days of the week selected in the WEEK DAYS range.
At the moment, the date that the formula steps from is always the start date.
For example, although 03/01/2022 (UK) is a Monday, if the WEEKDAY range is selected to be Thursdays and Fridays, with a rotation of 4 weeks, then the result should give me the result:
Start Date
03/01/22
End Date
10/03/22
Week Rotation
8 (weeks)
Weekdays
Thursday
Fridays
Desired result:
06/01/22
07/01/22
10/02/22
11/02/22
07/03/22
08/03/22
The formula I am using so far is:
=SEQUENCE(B8,1,A5,A8*7)
But I feel like with FILTER, there is perhaps a way of me getting the desired result.
Along these lines?
=FILTER(SEQUENCE(B8,1,A5,A8*7),WEEKDAY(SEQUENCE(B8,1,A5,A8*7),2))
Your help would be highly appreciate- I've spent many hours trying to solve this one going forward and backward with all sorts of bulky formulas!!!
Link to live spreadsheet.
https://docs.google.com/spreadsheets/d/1W3LSAjrshz3Mil6dsYVzKmR4fuL0Nojptl778ppTaEY/edit?usp=sharing
try:
=FILTER(SEQUENCE((B5-A5)/7*A8, 1, A5),
REGEXMATCH(TEXT(SEQUENCE((B5-A5)/7*A8, 1, A5), "ddd"),
TEXTJOIN("|", 1, LEFT(B11:B15, 3))))
update:
=FILTER(SEQUENCE(B5-A5, 1, A5),
REGEXMATCH(""&ROUNDUP(SEQUENCE(B5-A5)/7),
"\b("&JOIN("|", SEQUENCE(12, 1, 1, A8))&")\b"),
REGEXMATCH(TEXT(SEQUENCE(B5-A5, 1, A5), "ddd"),
TEXTJOIN("|", 1, LEFT(B11:B15, 3))))
What date time format is this : 735715:37344280
<ExecDateTOD Friendly="Monday April 27, 2015 10:23:00am">735715:37344280</ExecDateTOD>
It's found in C:\Windows\Performance\WinSAT\DataStore\file_name.xml, and is the date time when the Windows Experience Index Assessment test was run.
Any idea how it's structured and can be edited? I need to change it to a previous years Date.
It seems that this format is called VariantTime, in MSDN the call to convert time is called VariantTimeToSystemTime. So it may be number of days, with decimal part after the :.
For the timestamp 735715:37344280
The first number (the one before the colon) is the number of days since the year 0:
735715 / 365 = 2015.66
The second number (the one after the colon) is the number of milliseconds that have passed within the current day.
37344280 / (1000*60*60) = 10.37 hours since start of day
So you can just subtract 365 days from the first number to obtain the previous year like this:
<ExecDateTOD Friendly="Monday April 27, 2014 10:23:00am">735350:37344280</ExecDateTOD>
Note that there were no leap years in either 2015 or 2014, so these year are exactly 365 days long.
Here is a link to a page with another <ExecDateTOD> tag where you can compare: http://www.scribd.com/doc/82935159/2012-01-30-16-00-49-986-Formal-assessment-Recent-WinSAT#scribd
I think that if you subtract 365 from that number, you'll be in previous year.
That number seems to be days since the year 0. The first part might be the number of days, taking into account leap years, etc). The second part the time coded in some way.
Once a week I need to run a report where I query an Access database for any product that will expire in 9 months or less. The way they want it calculated is to take the date 9 months into the future and return anything that expires at the end of that month or sooner. If it were simply 270 days or less, I'd have no problem. (I'd also have no problem if I could do it in Excel, but that's not an option for now).
I came up with a solution that works every month of the year, unless it happens to be March (more specifically between March 6th and April 5th).
< DateValue(Month(Date()+270)+1 & "/1/" & Year(Date()+270))
So basically I'm:
adding 270 days to today's date
extracting the resulting month
adding 1 to the month
putting it back together as a text string so I can use < the 1st of the following month
for the year, I'm using the year from the date +270 days so I don't end up using the current year by accident
The trouble is that for the date range above (which I unhappily discovered today), I land in December when I add 270 days, so the following month is in a different year. As a result, my report only produced items that already expired.
In other words, on March 5th, I would have needed a list of everything expiring prior to December 1, but on March 6th, I need everything before January 1 of the next year.
Is there a more effective way to do this that avoids this issue? I thought of using
You may have had DateDiff in mind, and it can be used:
Where DateDiff("m", Date(), [YourDateField]) Between 0 And 9
However, that will ignore an index you might have on [YourDateField].
This, however, will include products that expired previously in the current month.
The alternative is DateSerial as Hans showed but he forgot that in SQL Date() must be used and that only those products that will expire should be listed:
Where [YourDateField] Between Date() And DateSerial(Year(Date()), Month(Date()) + 10, 0)
Use the DateSerial Function to compute the future date you need.
Here is a demonstration in the Access Immediate window which computes the date 9 months from today:
? Date
3/6/2015
? DateSerial(Year(Date), Month(Date) + 9, Day(Date))
12/6/2015
However, as I understand your requirement, you actually want dates from that entire month. In that case you can compute the first of the month which is 10 months from today and ask for everything less than that date.
? DateSerial(Year(Date), Month(Date) + 10, 1)
1/1/2016
You can include that expression in your query like this ...
WHERE expire_date < DateSerial(Year(Date()), Month(Date()) + 10, 1)
I am trying to develop a scheduling application that needs to represent rules such as "this event occurs on the 2nd and 4th Wednesdays of the month" or "this event happens on odd-numbered Saturdays of the month (i.e. the 1st, 3rd, and 5th Saturday).
To that end, I need to write a function in T-SQL that takes a Date input and returns an integer representing which occurrence-in-month of the dayname falls on that date.
For example, if I send the function 2012 DEC 21, it would return 3, because December 21, 2012 falls on the 3rd Friday of that month. Given 2012 DEC 29, it would return 5, since December 29, 2012 falls on the 5th Saturday of that month.
I'd like to do this without recourse to a prepopulated calendar table. I might want to use the function to work with historical dates, e.g. to compute which Wednesday of the month July 16, 1958 was.
Try this:
SELECT ((DATEPART(d, #input) - 1) / 7) + 1
We don't care about the actual day of the week, just the number of days past the first of the month (which is the day value - 1). Then an integer divide by 7 to get the number of weeks past the first of the month, and finally + 1 to have it start at 1 instead of 0.
Since "mm" displays the month, I wasn't sure
Format(now + 1, "mm")
will now + 1 month or + 1 day
Which one is correct?
Now + 1 adds one day. Doesn't matter how you're formatting it.
Dates are stored internally as the whole part of a real number, and are calculated as the number of days since Dec 30, 1899.
So today, Sept 20, 2012, is stored internally as 41172. Tomorrow will be 41173.
And in case you're wondering, time is stored as the decimal part of the number, and is calculated as the percent of the day. So 41172.5 would be noon today.
Don't guess about it. Use the function built specifically for this, DateAdd. See VB6 help topic on DateAdd for the complete details.
Date = DateAdd("m", 1, Now)