K_GOWTHAM
(GOWTHAM.K)
October 18, 2023, 5:49am
1
Hi, UiPath forum
I need to get the week number of the year, the first , and last day date of the week for the given date.
can you please help me to get this?
Sample Input
Input = 18.10.2023 current week
Input = 21.10.2023 current week
Input = 25.10.2023 Next week
Output
W42_16.10.2023 - 22.10.2023
W43_23.10.2023 - 29.10.2023
Gokul001
(Gokul Balaji)
October 18, 2023, 5:55am
2
Hi @K_GOWTHAM
This expression will get the Week Number in Integer
CInt(System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(New Datetime(2023,10,18),System.Globalization.CalendarWeekRule.FirstDay,DayOfWeek.Sunday).ToString)
First Date of the week
New dateTime(Now.Year,1,1).AddDays(7*(CInt(System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(New Datetime(2023,10,18),System.Globalization.CalendarWeekRule.FirstDay,DayOfWeek.Sunday).ToString)-1)-CInt(New dateTime(Now.Year,1,1).DayOfWeek)+1)
Last date of the Week
New dateTime(Now.Year,1,1).AddDays(7*(CInt(System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(New Datetime(2023,10,18),System.Globalization.CalendarWeekRule.FirstDay,DayOfWeek.Sunday).ToString)-1)+7-CInt(New dateTime(Now.Year,1,1).DayOfWeek))
Kindly find the video link
CultureInfo.CreateSpecificCulture(“en-US”).Calendar.GetWeekOfYear(New Datetime(2021,10,25), CalendarWeekRule.FirstFullWeek,DayOfWeek.Monday)
ensure
System.Globalization is added to the imports
set the locals to your present locals
About the week rule enum also have a look here:
And here:
[grafik]
CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(New Datetime(2021,10,25), CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday)
Regards
Gokul
2 Likes
@K_GOWTHAM
inputDate As Date = DateTime.ParseExact("25.10.2023", "dd.MM.yyyy",
CultureInfo.InvariantCulture)
The week number of the year
weekNumber As Integer = Calendar.GetWeekOfYear(inputDate,
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)
Find the first day of the week (Monday)
firstDayOfWeek As Date = inputDate.AddDays(DayOfWeek.Monday -
inputDate.DayOfWeek)
outputString As String = String.Format("W{0}_{1:dd.MM.yyyy} - {2:dd.MM.yyyy}",
weekNumber, firstDayOfWeek, lastDayOfWeek)
Output the result
WriteLine(outputString)
1 Like
@K_GOWTHAM
“W”+Cstr(Math.Round(Now.DayOfYear/7))+“_”+Now.AddDays(-CInt(Now.DayOfWeek)+1).ToString(“dd.MM.yyyy”)+“-”+Now.AddDays(CInt(Now.DayOfWeek)+1).ToString(“dd.MM.yyyy”)
output is “W42_16.10.2023_22.10.2023”
try this
1 Like
Yoichi
(Yoichi)
October 18, 2023, 6:08am
5
Hi,
How about the following?
varDate = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(strData,"\b\d{2}.\d{2}.\d{4}").Value,"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)
Then
varStartDate = varDate.AddDays(CInt(1-varDate.DayOfWeek))
varEndDate = varDate.AddDays(7-CInt(varDate.DayOfWeek))
weeknumber = System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(varDate,System.Globalization.CalendarWeekRule.FirstDay,DayOfWeek.Sunday)
Sequence2.xaml (8.1 KB)
Regards,
1 Like
system
(system)
Closed
October 21, 2023, 6:09am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.