Assign previous week in yyyy/WW to variable

Hello All,

How do get the previous week (current week no (-1) ) in yyyy/WW format to a variable

Thanking you

1 Like

Hello,

You can try this:
DateTime.Now.AddDays(-7).ToString(“yyyy/MM”)

Thanks!
Athira

Yes it worked.

how do I also get yyyy/WW
WW is week number of the year

Hi

Use this expression to get your output

str_weeknumber = DatetimeFormatInfo.CurrentInfo.Calendar.GetweekOfYear(Datetime.Now.AddDays(-7), DatetimeFormatInfo.CurrentInfo.CalenderWeekRule, DatetimeFormatInfo.CurrentInfo.FirstDayOfWeek).ToString

Cheers @Yugal_Raju


we would init with new statement

But it’s working fine even without initialising @ppr

DateTimeFormatinfo is not being declared.

Also I would like the date to come as 2022/14 - yyyy/WW

ensure following:
grafik

check with this sample workflwo
weeknumber.zip (1.1 KB)

Cheers @Yugal_Raju

Hi @Yugal_Raju ,
import System.Globalization

strPrevWeek=Now.Year.ToString()+"/"+DateTimeFormatInfo.CurrentInfo.Calendar.GetweekOfYear(Datetime.Now.AddDays(-7), DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek).ToString()

or

strPrevWeek=Now.Year.ToString()+"/"+System.Globalization.DatetimeFormatInfo.CurrentInfo.Calendar.GetweekOfYear(Datetime.Now.AddDays(-7),System.Globalization.DatetimeFormatInfo.CurrentInfo.CalendarWeekRule,System.Globalization.DatetimeFormatInfo.CurrentInfo.FirstDayOfWeek).ToString()

Regards,
Arivu

agreed @Palaniyappan due
DateTimeFormatInfo.CurrentInfo.Calendar vs. new DateTimeFormatInfo().Calendar

1 Like

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