To get week no with prefix 0 for weekno

Hello Everyone,

How can we get the week no using this format

startDate = New DateTime(2023,01,29)
targetDate = New DateTime(2023,02,05)
((CInt(Math.Floor((targetDate-startDate.AddDays(CInt(-1*startDate.DayOfWeek))).TotalDays)) \7-1)).ToString

So it returns 1 currently

How can we get it as 01

So that for all Week no between 1 to 9 it should prefix 0

Filling up with 0 we would do for strings like:
grafik

Hi @ppr this approach will add for all 0

How can we define the condition that only till week 9 its prefixed not for all of them

it will fill up when needed

Hi @anmita

How about this expression

If(((CInt(Math.Floor((targetDate-startDate.AddDays(CInt(-1*startDate.DayOfWeek))).TotalDays)) \7)+1).ToString.Count=1,"0"+CStr((CInt(Math.Floor((targetDate-startDate.AddDays(CInt(-1*startDate.DayOfWeek))).TotalDays)) \7)+1),CStr((CInt(Math.Floor((targetDate-startDate.AddDays(CInt(-1*startDate.DayOfWeek))).TotalDays)) \7)+1))

Regards
Gokul

Hello @anmita
Just try by adding (“D2”) in your expression

((CInt(Math.Floor((targetDate-startDate.AddDays(CInt(-1*startDate.DayOfWeek))).TotalDays)) \7-1)).ToString("D2")

Make the end…

.ToString(“D2”)

Hi @Gokul_Jayakumar

Thanks for approach

Can you let me know if for 11 will it be shown as 011 because that would be incorrect

Thanks @Gokul001

@anmita
Check this

Thanks @Gokul_Jayakumar :+1:t2:

Thanks @postwick

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.