1

How to calculate date for current week Friday in Teradata? I need a general function that can calculate date for friday for any week. thanks

user3438498
  • 211
  • 3
  • 11
  • 21
  • What's your TD release? And how do you define a week, starting on monday or sunday? – dnoeth Nov 13 '14 at 16:46
  • Teradata version 13.10.0214 I am considering week as from Friday to Friday. For this case I want Avg. Amount for Last 6 months. So whenever report is run on any day of week it should consider current day as Friday no matter report is run on which day – user3438498 Nov 13 '14 at 16:57

1 Answers1

1

In TD14 there's Oracle's NextDay, to get the next friday:

NEXT_DAY(CURRENT_DATE-1, 'FRI')

Before you can calculate it based on a function named day_of_week (or td_day_of_week):

(CURRENT_DATE + 7) - td_day_of_week(CURRENT_DATE + 1)
dnoeth
  • 59,503
  • 4
  • 39
  • 56