Would it be possible to get same day of week last year using Excel? please below example:
Input: Monday 9 Nov 2015 | Output: 10 Nov 2014
Thanks
Simply subtract 52 full weeks with 7 days = 364 days. So if the date is in A1, the formula =A1-364 will get the date exactly 52 weeks before, which is the same day of week in the year before.
To show that it works even for leap years, try the following:
You see the formula date - 364 (=A2-364, =A3-364, ...) always gets the same day of week a year before. That is because it gets the day minus 52 full weeks (52 * 7 days) before. In leap years it gets a different day but the same day of week.
Try this:
=DATE(YEAR(A1)-1,MONTH(A1),DAY(A1))+WEEKDAY(A1)-WEEKDAY(DATE(YEAR(A1)-1,MONTH(A1),DAY(A1)))
It returns the closest date within a week. A1 is the cell with this year's date.
Related
I am trying to get week numbers ( resetting at 1 for each month) as per ISO format for each month in 2019.For example I am interested in getting
All dates in July 2019: week 1 to 4,
All dates in Aug 2019 : week 1 to 4 and so on.
I first created the calculated field (Week_Number_ISO) to get the overall week number in year 2019.I used the following formula;
DATEPART('iso-week',[ Date]) which works as intended.
To get the monthly week number I used the following formula
INT((DATEPART('day',[Created Date])-DATEPART('iso-weekday',[Created Date])+7)/7)+1.
(Idea was to calculate the date of the first day of each week & then divide by 7 and take the integer part)
As per the ISO format, shouldn't July 29 to 31st be a part of week 4 for July?But the formula is showing it as week 5 for July 2019.I feel I am missing something in the formula or am missing something about ISO week number resetting at 1 for each month.
Can someone help me?
Here is an example of the dates in July 2019 and the associated week numbers.
Why would July 28th-July 31st 2019 be considered week 4?
I need help on calculating my start date for my report date parameters.
The end date will always be the last Sunday, here: =DateAdd("d", 1 - WeekDay(Today(), 1), Today())
What I need help with is how to write a formula to go back 6 months from today and pick the 1st Saturday in that range..
Thanks in advance.
Assuming your start day is a Sunday then you can use this...
=DATEADD(
DateInterval.Day,
7 - WEEKEDAY( DATEADD(DateInterval.Month,-6,Today()), FirstDayOfWeek.Sunday),
DATEADD(DateInterval.Month,-6,Today())
)
This works as follows
WEEKEDAY( DATEADD(DateInterval.Month,-6,Today()), FirstDayOfWeek.Sunday)
Takes today's date, subtracts 6 months and then finds out what daynumber that is. Running that today (2018-11-08) gives use (2018-05-10) which is a Thursday, this is day number 5
Saturdays are day number 7 (if your first day of week is a Sunday). As there can be no higher number than 7 we can do a simple subtraction of 7 minus the day number we landed on (from above) which gives us a required adjustment of 2 days.
Finally the outer DATEADD function simply says add our calculated 2 days to the date 6 months ago.
Hope that makes sense!?
If the first day of the week is not a Sunday for you then you may have to do some Mod% calc on the second argument to calculate the correct number of days to adjust by.
I need to convert the week field into Date(mm/dd/yyyy).
Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9 Week 10 Week 11 Week 12 Week 13 Week 14 Week 15 Week 16 Week 17 Week 18 Week 19 Week 20 Week 21 Week 22
Actually I have dragged the date field into Columns and I selected the week.
I need to convert this into Date (mm/dd/yyyy). How to achieve this?
Directly in your sheet, if you right click on your date field, you'll get a menu with the following options: "Filter", "Show quick filter", etc. You'll also see an option which says "Day.... May 8, 2011". That gives you a full date.
But if you want that date to have the "mm/dd/yyyy" format, you'll need to change it from the left pane. Right clicking on your date dimension provides the following option: "Default Properties/Date Format". You have a few default formats in there, including a custom formatting where you could make it mm/dd/yyyy.
Olivier
I think you want this formula: DATETRUNC('week', [day], 'Monday'), assuming your week starts on Monday. You may also need to change the format to m/d/y in the left-hand pane, per Jim Dehner: https://community.tableau.com/thread/234590
For dates 1/2 - 1/9/2017 this will return (Monday) 1/2/2017. For 1/9 - 1/16, it will return 1/9/2017, etc.
I believe this post could help you out: https://community.tableau.com/s/question/0D54T00000C6Y9TSAV/how-to-convert-week-number-into-a-date-format
Basically you can use this formula:
DATETRUNC('week',DATE(DATEADD('week', WEEK(TODAY())-1, DATE("01/01/"+STR(YEAR(TODAY()))))))
Here's a bit of fun.
If we peek at the dotnet source code, the following comment can be found at the head of the file TimeSpan.cs:
...while a year can contain 365 or 364 days
Should I be worried?
I don't know what the source code comment refers to, but there are some more exotic calendars where a year only has 364 days, e.g. a leap week calendar:
A leap week calendar is a calendar system with a whole number of weeks every year, and with every year starting on the same weekday. Most leap week calendars are proposed reforms to the civil calendar, but some - such as the ISO week number calendar - are simply conveniences for specific purposes.
The ISO calendar in question is a variation of the Gregorian calendar that is used (mainly) in government and business for fiscal years, as well as in timekeeping. In this system a year (ISO year) has 52 or 53 full weeks (364 or 371 days).
One advantage is the better divisibility. A year with 364 days can be divided into 13 equal months. Other calendars using such a system are according to Wikipedia:
International Fixed Calendar
Pax Calendar
Perhaps they were talking about the maximum day index in a year when the day index starts at zero?
In general, you should not be too worried. There are some years back in time with much less than 364 days! Basically, the crux is the change from Julian to Gregorian calendars, which happened at differing times at differing locales. In the US, the month of interest is Sep 1752,
jlouis#illithid:~$ cal sep 1752
September 1752
Mo Tu We Th Fr Sa Su
1 2 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
since the US was part of the British Empire at that time, see
http://en.wikipedia.org/wiki/Gregorian_calendar#Adoption
for further explanation.
Aside: This is why you should generally not try to do your own date handling. It is pure pain to get all the intricacies correct.
West Samoa crossed the dateline in 2011, skipping December 30th, going from December 29th directly to December 31st.
So technically they had a 364 day year.
Perhaps they meant 365 or 366 days? As far as I know 364 days in a year is not acceptable.
No it can not. Maybe you should worry. Although the number of integer weeks x days per week = 52 x 7 = 364
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
If someone were to say something happens in the first or last week of some month, how would you define that span?
Background
I'm working on a library that needs to handle this kind of thing in an intuitive way, but my intuition doesn't claim one case or the other.
I can make it select different behavior but still need a good default.
For a concrete example I'll just to pick an random month: July 2008
s m t w r f s
--------------------
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
(Note: I'll assume the week starts with Sunday but the question could be asked re Monday as well)
What span is the first week of the month?
June 29 - July 5 -- the week that includes the first
July 6 - 12 -- the first week that is all the way into the month
The second week is just the 7 days following the first right?
What span is the last week of the month?
July 27 - Aug 2 -- ditto but the last day
July 20 - 26 -- ditto but the last week
Non wiki comments welcome
There is no answer because it varies even inside a country.
However, this source seems to think it's defined by the ISO standard as the first week that contains a thursday. However the above source says that the ISO standard does not list a specification for 'first week of the month'
More than 300 chars - sorry!
The ISO 8601 standard defines the first week of the YEAR as:
calendar week number
ordinal number which identifies a calendar week within its calendar year according to the rule that the first
calendar week of a year is that one which includes the first Thursday of that year and that the last calendar
week of a calendar year is the week immediately preceding the first calendar week of the next calendar year
There is nothing in ISO 8601 about the first week of the month because, as has been noted, the definition varies by country (and even by company, for example). Oh, and the standard says that weeks start on Monday.
If you are building a library, you should allow the user to choose how they want to handle it either by having methods that return the first/last full/partial week of the month or by passing an argument that indicates whether you want the full/partial week. Clearly document whichever is the default if you provide methods that don't require the specification.
public Week GetFirstFullWeekOfMonth( DateTime forDate ) { }
public Week GetFirstPartialWeekOfMonth( DateTime forDate ) { }
Or
public Week GetFirstWeekOfMonth( DateTime forDate, bool includePartial ) {}
The first week of the month is the first week that is all the way int the month
July 6 - 12
The first week of the month is the week that includes the first
June 29 - July 5
The last week of the month is the week that includes the last day
July 27 - Aug 2
The last week of the month is the last week that is all the way int the month
July 20 - 26
My definition would be the first week is the week of the first working day in the month,
and likewise the last week is the week of the last working day in the month.
The first week of the month is the first week that owns 4 or more days of the defined week period. (Not really but I thought I'd throw it in as an option)
The first week of the month is week 0 - the week that has the first day of the month.
The last week is the week with the last day of the month
Hence the weeknumber of the last week of july IS THE SAME as the weeknumber of the first week of august
** UNLESS **
the month in question ends on the last day of the last week, in wich case the following month would start on the first day of the new week and have a different weeknumber
:)
There's a fairly obvious option you are missing. The first week of the month is the seven days starting with the first day of the month. Hence, in your example, the first week would be Tuesday, the 1st through Monday, the 7th. This way, the first through 4th weeks would always be fully contained within the month, and only the 5th week would cross over.
Talk to your users and ask them what they think it means when the program says to them "First week of the month" and "Last week of the month".