hacky
(NotHacker)
January 3, 2019, 7:55am
1
Hi
Please help me with the problem.
Problem:- I want to get the number of the current week of the month (not year).
Like if October starts from Monday, 9th October shall be in second week, 15 shall be the second week and so on.
I am sure it’s a silly doubt, but I would be glad if you could help.
Thanks and regards,
@hacky
1 Like
Here is the C# code -
static int GetWeekNumberOfMonth(DateTime date)
{
date = date.Date;
DateTime firstMonthDay = new DateTime(date.Year, date.Month, 1);
DateTime firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
if (firstMonthMonday > date)
{
firstMonthDay = firstMonthDay.AddMonths(-1);
firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
}
return (date - firstMonthMonday).Days / 7 + 1;
}
Test:
Console.WriteLine(GetWeekNumberOfMonth(new DateTime(2014, 1, 6))); // 1
Console.WriteLine(GetWeekNumberOfMonth(new DateTime(2014, 1, 30))); // 4
Console.WriteLine(GetWeekNumberOfMonth(new DateTime(2014, 2, 1))); // 4
Console.WriteLine(GetWeekNumberOfMonth(new DateTime(2014, 2, 3))); // 1
Refer this post
Look here
you can reproduce similar logic in UiPath.
// variable type of in_Today DateTime (this will be your input datetime)
// variable type of Basedate is DateTime
// variable type of week is Int64
Assign Basedate = new DateTime(in_Today.Year, in_Today.Month, 1)
Assign week = DateAndTime.DateDiff(DateInterval.WeekOfYear ,Basedate, in_Today, FirstDayOfWeek.Monday,FirstWeekOfYear.Jan1)
actual value = week+1
hacky
(NotHacker)
January 3, 2019, 11:24am
4
@Karthick_Settu , can you please provide me with the simple flow? since I am not able to do this.
hacky
(NotHacker)
January 3, 2019, 11:25am
5
@KarthikByggari ,
This C# code looks perfectly fine. But I might need the simple flow demonstrating the same.
Kindly help.
Check this file.
Main.xaml (7.1 KB)
10 Likes
system
(system)
Closed
January 6, 2019, 11:41am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.