Stanley's Tech Notes

Tuesday, March 09, 2010

Last Business Day (Monday to Friday)

(1) The date range:

[GHA_Report].[Auth_Header].[Entered_Date]

between

if (_day_of_week(current_date, 7) = 2)
then (DATEADD({dd}, DATEDIFF({dd},3,current_date), 0))
else (
if ( _day_of_week(current_date, 7) = 1)
then(DATEADD({dd}, DATEDIFF({dd},2,current_date), 0))
else(DATEADD({dd}, DATEDIFF({dd},1,current_date), 0))
)

and

if ( _day_of_week(current_date, 7) = 2)

then (dateadd({ms},-3,DATEADD({dd}, DATEDIFF({dd},2,current_date), 0)))
else (
if ( _day_of_week(current_date, 7) = 1)
then(dateadd({ms},-3,DATEADD({dd}, DATEDIFF({dd},1,current_date), 0)))
else (dateadd({ms},-3,DATEADD({dd}, DATEDIFF({dd},0,current_date), 0)))
)


(2) Last Business Day Display

if (_day_of_week(current_date, 7) = 2)
then (DATEADD({dd}, DATEDIFF({dd},3,current_date), 0))
else (
if ( _day_of_week(current_date, 7) = 1)
then (DATEADD({dd}, DATEDIFF({dd},2,current_date), 0))
else (DATEADD({dd}, DATEDIFF({dd},1,current_date), 0))
)


0 Comments:

Post a Comment

<< Home