问题
I am creating a package which will store a report's generation date. on basis of that date need to derive the next wednesday date. Ex: report date is 11/11/2019 so wed date should be 13/11/2019. urgenty needed
回答1:
This Derived Column Expression should provide the next Wednesday's date.
DATEADD("DAY",((1 + DATEDIFF("DAY",(DT_DATE)"1/1/1970",GETDATE())) / 7) * 7 + 6,(DT_DATE)"1/1/1970")
Parts (inside out).
- Days since 1/1/1970 + 1.
- (Divide by 7) (Implicit Cast to Int) (Multiple by 7) will round it to last Thursday.
- When added days back to 1/1/1970 (+6 days more) will move to next occurring Wednesday.
Notes
- Without the initial 1 day offset, If GETDATE() is a Wednesday, the result will be GETDATE()'s date.
- GETDATE() can be swapped out with GETUTCDATE() or a date Variable as needed.
- The +6 can be moved back to +5 if a Tuesday is desired.
来源:https://stackoverflow.com/questions/58913536/ssis-how-to-calculate-next-wednesday-based-on-any-given-date-using-ssis-derived