Weeknum that doesn't start from 1st every year - excel

How can i start weeknum from first week in 2018 and go on through 2019, 2020, 2021, 2022... without starting the count from 1 every year. Ex: if 2018 has 44 weeks i want the weeknum(1-1-2019) to return 45 not 1 and so on.

If you Week starts on Monday use:
=INT((A1-"1/1/2018")/7)+1
If your week starts on Sunday:
=INT((A1-"1/1/2018"+1)/7)+1

Related

Excel: calculate which occurance of a weekday, within the month, from any given date e.g. fifth Friday

I am not very good at Excel. In the NHS (UK) we often schedule activity by looking at the columns on a calendar (e.g. All day theatre list Mondays week 1,3,5). This means on the first Monday, third Monday and if present fifth Monday. Using a printed calendar you can see the columns, for example Mondays in Jan 2023 where there are five.
When planning, it would be great to have a formula that would accept a date, and return the ordinal of the weekday for that month e.g.
Jan 02 2023 = 1
Jan 28 2023 = 4
Jan 29 2023 = 5
Jan 30 2023 = 5
I have searched and found the WEEKNUM function, but this counts rows on the calendar not giving the result I need.
Any help gratefully received
Kind Regards Gavin Holt
This should return those values:
=-INT(-(DAY(YourCellWithTheDate))/7)

Excel add hours to date excluding weekends and holidays

I would like to add hours on a start date and skip weekends and holidays in an Excel file.
The hours would be 24, 36 and 48.
So if the start date and time are 4 Mar 2019, 13:42, the end date and time should be :
24 hours: 5 Mar 2019, 13:42
36 hours: 6 Mar 2019, 01:42
48 hours: 6 Mar, 2019, 13:42
I am now using this formula:
=WORKDAY(E2,G2/24,Holidays!$A$2:$A$18)+MOD(E2,1)
E2 is the start date and time in mm/dd/yy hh:mm format, G2 is the number of hours, Holidays!$A$2:$A$18 is the range of holiday.
This formula works totally fine for 24 hours and 48 hours, however, it is not working for 36 hours. It would be much appreciated if someone would help me to solve this problem.
Construct a simple date from addition and then convert it to the workday.
=WORKDAY(A2+B2/24-1, 1, Holidays!$A$2:$A$18)+MOD(A2+B2/24, 1)

Excel IF critreria

I have a request where I am trying to determine if we hit our metrics with tickets opened to our company. Essentially we have to respond to cases within by the next business day, the exception here is if the ticket is opened after Friday 18:00 we get to wait till Tuesday end of day 18:00
So my original thinking was if a ticket:
1) a ticket is not opened, Fri, Sat, Sun then if response time is less than 24 then we MET
2) a ticket is opened up after 18:00 Friday then we have till EOD Tuesday 18:00 - it does not matter what time within Friday 18:00 to Sunday 23:59.
3) If a ticket is opened up Friday 00:00-117:59 then we have until Monday 18:00
Problem is I don't know how to calculate what the time should be, in a perfect situation a case is opened on Friday 17:00 and we have exactly 72 hours to respond. But cases are opened anytime throughout the weekend and how do I subtract that from the 72 to determine if we met or not.
Here is an example of my table
Month Year Day Time Hours Met/Miss
January 2017 Wed 15:20 19.77
January 2017 Tue 9:02 2.04
January 2017 Tue 11:35 0
January 2017 Fri 10:37 0.19
January 2017 Fri 17:48 89.06
January 2017 Mon 0:33 0.03
Any suggestions, I am also going to wrap this into VBA so that a macro does all this work.
Should know that I am only a beginner-intermediate in Excel and VBA - sorry
You're going to be better off if you can input your ticket open time as a date, then use a VBA function to calculate a due date. Then you can either calculate a ticket closed date and compare, or calculate a time difference and compare. Hypotheically you don't actually need your day of month because you only care about day of week, but it would be best to include day of month as shown below.
Edit
The same functionality of the VBA function below can be achieved by the worksheet equation:
=IF(WORKDAY(WORKDAY(H2,1,Holidays),-1,Holidays) = ROUNDDOWN(H2,0), WORKDAY(H2,IF(HOUR(H2)>=18,2,1),Holidays)+18/24, WORKDAY(WORKDAY(H2,-1,Holidays),2,Holidays) + 18/24)
Where the H column has ticket opened dates and Hol is your list of holidays.
It may or may not be easier/better to use this VBA function which basically does the same thing without holidays. The VBA function can be friendlier to future programming.
Function CalculateDueTime(OpenedTime As Date)
Dim DueTime As Date
Dim wkd As Integer
wkd = Weekday(OpenedTime, vbSunday)
If wkd = 1 Then
'Zero the hours, Add 2 days to get from Sunday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 2, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
ElseIf wkd = 7 Then
'Zero the hours, Add 3 days to get from Saturday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 3, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
Else
'Add an hours portion to see what day we arrive at
'The reason this works is because what you actually have is an offset in your end-of-day from midnight to EOB.
'So we're accounting for that offset by adding 6 hours then adding 24 to get to our due day,
'then defining 18:00 as our due time on that due day.
DueTime = DateAdd("h", 6 + 24, OpenedTime)
'Whatever day we arrived at above, zero the hours and add 18
DueTime = DateAdd("h", 18, DateAdd("h", -Hour(DueTime), DueTime))
wkd = Weekday(DueTime, vbSunday)
If wkd = 7 Or wkd = 1 Then
'If our due date lands on the weekend
'we can always resolve it by adding 2 days
'Opened Thur due Sat becomes due Mon
'Opened Friday due Sat becomes due Mon
'Opened Friday due Sunday becomes due Tues
DueTime = DateAdd("d", 2, DueTime)
End If
End If
CalculateDueTime = DueTime
End Function
This gives the the following results...
It doesn't really matter, but if you're curious about the date formatting here is the custom format I used.

Find the end-of-month date from any date entered in MS Excel

I need to take the date from one cell, find the end of the month that that date falls into, then add one calendar month.
Example:
Enter jan 13: jan 13 end of month is Jan 31, + 1 month is Feb 28 (or 9 on leap year).
Feb 19: = March 31
March 2 = 30 April
March 30 = 30 April
March 31 = 30 April
etc etc
Is there an excel formula that will do this? I don't want any macro/ VBA stuff.
If you have 2007 or later than:
=EOMONTH("3/30/2016",1)
Use the Date function, add one to the month and set the Day to zero. This gives the last day of the month. To get the last day of the next month add two to the month.
=DATE(YEAR(E3),MONTH(E3)+1,0)
=DATE(YEAR(E3),MONTH(E3)+2,0)

how to calculate the number of the week in a year?

I would like to calculte the number of the week in a year. I see this post
In this post the acepted answer use this code:
public static int GetIso8601WeekOfYear(DateTime time)
{
// Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll
// be the same week# as whatever Thursday, Friday or Saturday are,
// and we always get those right
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
{
time = time.AddDays(3);
}
// Return the week of our adjusted day
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
However I see a problem. The number of the week is repeated if the last day of a month is in Sunday.
For example, the last day of March of 2013 year is in sunday. This week is the number 13th, is correct. But in April, how C# use always 6 weeks in a month to calculate the number of week, the first week of april has not any day of april, because all the days belong to march because the last day of the week is 30th March. So C# says that the first week of april is th 15th week, but this is incorrect, it has to be 14th.
So I would like to know if there are any way to calculate the number of a week in a right way.
EDIT:
I mean this:
In march, the last week is this:
25 26 27 28 29 30 31
This is the 13th, is correct.
In april, the first week is:
1 2 3 4 5 6 7
And this week is calculated as 15th.
So if I see the march calendar the last week is calculated as 13th and if I see the april calendar the last week of march is caluclated as 14th. This is incorrect.
SOLUTION:
DateTime dtCalendar = Calendar.DisplayDate;
int gridRow = (int)GetValue(Grid.RowProperty);
// Return the week of our adjusted day
int wueekNumber= System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(dtCalendar, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
if (dtCalendar.DayOfWeek == DayOfWeek.Monday)
{
gridRow = gridRow - 1;
}
Text = (weekNumbe r+ gridRow - 1).ToString();
Thanks.
The problem is that you are using the wrong CalendarWeekRule. To get the result you want you should use FirstDay. I have seen various codes in internet saying that you should use FirstFourDayWeek but, after some testing, I realised that the "right one" is FirstDay. I have tested it with your example and it delivers the right result: 14th week.
int targetYear = 2013;
DateTime targetDate = new DateTime(targetYear, 4, 1);
int week = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(targetDate, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);

Resources