Here’s the formula I’ve now implemented on an import scenario for equipment time (Source in my case is Excel). This returns the ISO Year and week for a given date in the same yyyyww format as Acumatica. The same formula will also work in a Generic Inquiry. You’ll need to delete the comment lines, and replace all occurrences of [Date Entry] with the name of your date column.
-- ISO 8601 Week ID for Acumatica GI or Import Scenario
-- Returns the weekID in yyyymm format for a transaction date.
-- Replace all occurrences of [Date Entry] with the column name of your transaction date.
-- Comment lines will need to be removed.
-- NB. DayOfWeek() function returns 1 for Sunday, 7 for Saturday
-- Scenario 1: If following calendar year starts on Tue (3), Wed (4) or Thu (5), then last up to 3 days of this calendar year may be week 1 of following year
=Iif(
(
DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+1)+'-01-01')) >= 3 and
DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+1)+'-01-01')) <= 5 and
DateDiff('d',CDate([Date Entry]),CDate(CStr(Year(CDate([Date Entry]))+1)+'-01-01')) +2 <= DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+1)+'-01-01'))
)
, CStr(Year(CDate([Date Entry]))+1) +'01'
,
-- Scenario 2: If this calendar year starts on Fri (6), Sat (7) or Sun (1), then first up to 3 days of this calendar year may be week 52 or 53 of last year
Iif(
(CDate([Date Entry]) = CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01') and DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')) = 1)
OR
(
DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')) >= 6 and
DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')) <= 7 and
DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')) + DateDiff('d',CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01'),CDate([Date Entry])) <= 8
)
, CStr(Year(CDate([Date Entry]))-1)
+ PadLeft(CStr(datediff(
'w'
,
DateAdd(
CDate(CStr(Year(CDate([Date Entry]))-1)+'-01-01')
,'d'
,Iif(DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))-1)+'-01-01')) <= 5
,2 - DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))-1)+'-01-01'))
,9 - DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))-1)+'-01-01'))
)
)
,
CDate([Date Entry])
)+1
),2,'0')
-- Scenario 3: Failing Scenario 1 or 2, it's a week in the same year.
, CStr(Year(CDate([Date Entry]))+0)
+ PadLeft(CStr(datediff(
'w'
,
DateAdd(
CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')
,'d'
,Iif(DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01')) <= 5
,2 - DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01'))
,9 - DayOfWeek(CDate(CStr(Year(CDate([Date Entry]))+0)+'-01-01'))
)
)
,
CDate([Date Entry])
)+1
),2,'0')
)
)