0

I am trying to rename the file appending previous Monday date to the filename.I am using the following expression for appending today's date

@[Dest_Dir] + "\\" + @[Dest_File] + "_" + (DT_WSTR,4)DatePart("yyyy", GetDate()) + RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) + ".xlsx"

Which is working fine but When i am replacing getdate() with getdate()-7 to get last Monday date(I run this every Monday) i am getting an error. can someone help me with the expression for previous Monday.

SqlLearner
  • 763
  • 8
  • 23
  • 37

1 Answers1

0

try this:

@[Dest_Dir] + "\\" + @[Dest_File] + "_"+  
(DT_WSTR,4) YEAR(DATEADD( "DD", -7, getdate()))+ 
RIGHT(  "0" + (DT_WSTR,2) MONTH( DATEADD( "DD", -7, getdate() ) ), 2)  
+RIGHT( "0" + (DT_WSTR,2) DAY( DATEADD( "DD", -7, getdate() ) ), 2)  + ".xlsx"

the returned format is:

dest_dir\dest_file_20160718.xlsx

removing seven days to getdate() using DATEADD

ɐlǝx
  • 1,384
  • 2
  • 17
  • 22