Get the week of a date field in BAQ

Edit: dateadd(week,datepart(wk,LaborDtl.ClockInDate)-1, DATEADD(wk, DATEDIFF(wk,-1,DATEADD(yy, DATEDIFF(yy,0,LaborDtl.ClockInDate), 0)), 0))

I want to get the week (either in WeekNum or Date Format or whatever) of a date field in BAQ but I’m not sure how to do it. There doesn’t seem to be any build in function to do this

1 Like

DATEPART( wk, YourdateTo look)

DATEPART info
Pierre

I get this error: Severity: Error, Table: , Field: , RowID: , Text: Invalid cast from ‘Int32’ to ‘DateTime’.Couldn’t store <41> in Calculated_Week Column. Expected type is DateTime.

The column is LaborDtl.ClockInDate which is a date format.

Edit: I’m trying to do this in a calculated field

Can you show a snapshot of the calculated field design?

Is your calc field type int? because DATEPART returns int

Pierre

2 Likes

Got it, my calculated field was a date field. Thanks a lot, will look at the function from there and update my post when I got a working expression!

1 Like