Solved

# Is there a way to get current weekID in a Generic Inquiry?

• 8 replies
• 423 views

Userlevel 4
+1
• Varsity I
• 121 replies

Hi All,

I want to add a condition to a generic inquiry to filter timecards created on last week. To do that I think that I would need to compare EPTimeCard.WeekID with current WeekId. Is there a way to populate Value field of GI with current WeekID ?

Thanks

icon

Best answer by Naveen Boga 5 December 2022, 12:52

View original

### 8 replies

Userlevel 7
+18

@charithalakshan49  I don’t think we can get the WeekID value in the Generic Inquiry but can get the StartWeek OR EndWeek like below.

Userlevel 4
+1

@Naveen Boga  Thank you. I will try it.

Userlevel 3

This formula will generate a WeekID. It uses DateAdd() and DayOfWeek() to get last week’s Monday, then uses that Monday to calculate the week number.

The formula cannot be used as a default value in a GI parameter, however it CAN be used as a GI condition or the default value in a report parameter.

Excel VBA

``=Year(DateAdd("d", -6 - Weekday(Date, 2), Date)) * 100 + Application.WorksheetFunction.Floor(DateDiff("d", CDate("1/1/" & Year(DateAdd("d", -6 - Weekday(Date, 2), Date))), DateAdd("d", -6 - Weekday(Date, 2), Date)) / 7) + 1``

Acumatica

``=Year(DateAdd(Today(),'d', -6 - DayOfWeek(Today()))) * 100 + Floor(DayOfYear(DateAdd(Today(),'d', -6 - DayOfWeek(Today()))) / 7) + 1``

Userlevel 3
+1

This is how I’ve done it in GI’s for This or Last weeks Timecards.

=IIf([AllWeeks] = 'Last' , [LastWeekStart], iif([AllWeeks] = 'Current' ,[ThisWeekStart],'' ))

Userlevel 4
+1

@greglang Great!. Thanks for sharing

Userlevel 3

Here is a better way to calculate WeekID in Acumatica. The end of the year gives the wrong number using the first method.

``=DateAdd(Year(DateAdd(Today(),'d',-6-DayOfWeek(Today()))) * 100 ) +Floor(  DateDiff('d',    Round(      DayOfWeek(CDate('1/1/'+DayOfYear(DateAdd(Today(),'d',-6-DayOfWeek(Today())))))/7,0    ),    DateAdd(Today(),'d',-6-DayOfWeek(Today()))  ) / 7)+ 1 ``

Userlevel 3

``=Year(DateAdd(Today(),'d',-6-DayOfWeek(Today()))) * 100 +Floor( DateDiff('d',  DateAdd(CDate('1/1/'+Year(DateAdd(Today(),'d',-6-DayOfWeek(Today())))),'d',7 *    Round(DayOfWeek(CDate('1/1/'+Year(DateAdd(Today(),'d',-6-DayOfWeek(Today())))))/7,0)  ),  DateAdd(Today(),'d',-6-DayOfWeek(Today()))) / 7 )+ 1``

Userlevel 4
+1

Hi @cmetzger. Thanks for sharing!