Hii Team ,
Have used below approach to find week no
Example
inputdata = “202428”
Input data contains the date which means in this example it is year 2024, month is 2 and date is 8th
WeekNo = CInt(math.Round(datetime.ParseExact(inputdata,{“yyyyMMdd”,“yyyyMd”} ,system.Globalization.CultureInfo.InvariantCulture).DayOfYear/7)+1)
But week no is giving error in this case because inputdata is not present in this format 20230120
Could someone guide in finding week no for the input data in the given format
Thanks team in advance
Parvathy
(PS Parvathy)
February 16, 2024, 8:15am
2
Hi @NISHITHA
Try this:
weekNo = CInt(Math.Ceiling(DateTime.ParseExact(inputData.Insert(4, "-").Insert(6, "-"), "yyyy-M-dd", CultureInfo.InvariantCulture).DayOfYear / 7.0))
Hope it helps!!
avejr748
(Ave Salvante Jr)
February 16, 2024, 8:35am
3
Hi @NISHITHA my approach to this was to first check the inputdata length as there is no guarantee that you will not receive a date like 202422 (Feb 2, 2024). If the length was 8 chars then its good to go. When it is 7 then use string manipulation to get the first 4 chars as the year, the 5th as the month, and the 6th and 7th as the day. If it is 6 then first 4 as the year, 5th is month and 6th is day. You get the idea… The challenge when it is 7 in length is then how to decide which is the month and day for ambiguous input like 2024111 (Jan 11 or Nov 1?) or 2024121 (Dec 1 or Jan 21?)
Any other approach that could suggest
1 Like
Parvathy
(PS Parvathy)
February 16, 2024, 9:14am
5
Hi @NISHITHA
What approach do you want?
Regards
@Parvathy thanks for reference but its giving exception
Parvathy
(PS Parvathy)
February 16, 2024, 9:24am
7
What are the exception you are getting @NISHITHA
Regards
@Parvathy am getting System.InvalidOperation Expression
For this date
inputdata = “202428”
rlgandu
(Rajyalakshmi Gandu)
February 16, 2024, 9:33am
9
@NISHITHA
weekNo = (New System.Globalization.CultureInfo("en-US")).Calendar.GetWeekOfYear(DateTime.ParseExact(inputData, {"yyyyMMdd", "yyyyMd"}, System.Globalization.CultureInfo.InvariantCulture), System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday)
whatever formats you have please mention in {“yyyyMMdd”, “yyyyMd”}
Parvathy
(PS Parvathy)
February 16, 2024, 9:38am
10
Hi @NISHITHA
Try this:
CInt(Math.Ceiling(DateTime.ParseExact("202428".Insert(4, "-").Insert(6, "-"), "yyyy-M-d", System.Globalization.CultureInfo.InvariantCulture).DayOfYear / 7.0))
Hope it helps!!
ppr
(Peter Preuss)
February 16, 2024, 9:43am
11
NISHITHA:
2024120
Parsing the datestring:
in the first case we get an exception as the pattern Mdd is ambiguous for the parser
In such cases we could think about fixing such dates with a RegeEx
But still can have some risks on those dates
yyyymd - 202412 - 2nd Jan 2024
yyyymd - 2024122 - which could be the 22th Jan 2024 or 2nd Dec 2024
Similar for a 6-digit length string we can do:
insert a 0 before and 0 afterwards
About: Weekno
We suggest to import System.Globalization to the namespaces and shortening the statement
A strategy could be to integrate within the flow a sorting out of all ambiguous dates and routing it back for manually inspections and corrections. But here we have to know more about the use case in general
1 Like
Thanks @Parvathy
This is working for the given scenario
1 Like
Thanks @ppr your right about the Observation
Will need to make changes
Parvathy
(PS Parvathy)
February 16, 2024, 10:27am
14
Hi @NISHITHA
If you find the solution for your query please mark my post as solution to close the loop.
Regards
Thor_Damon
(Thor Damon)
February 16, 2024, 12:18pm
15
NISHITHA:
CInt(math.Round(datetime.ParseExact(inputdata,{“yyyyMMdd”,“yyyyMd”} ,system.Globalization.CultureInfo.InvariantCulture)
Hi NISHITHA,
please give proper input value . then only we can able to calculate that the date format
system
(system)
Closed
February 19, 2024, 12:19pm
16
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.