Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

DateAdd / DateDiff: Find the last Tuesday encountered, Find coming Monday

$
0
0

Hi Ladies & Gents, 

I have a problem where I need to return two dates into variables. I want to return the last Tuesday we have passed through as well as the coming Monday.

Caveats (edge cases)

a) If it happens to be a Tuesday when the function is run, use that day, not the last Tuesday.  

b) If it happens to be Monday when the function is run, use that day, not the next Monday. 

I hope my examples will make clear what I am trying to achieve... 

Examples: 

edge case a:

If today is Tuesday 9/3/2013 return:

Tuesday 9/3/2013 and Monday 9/9/2013 11:59:99pm

-----------------------------------------

Edge case b:

If today is Monday 9/23/2013 return:

Tuesday 9/17/2013 and Monday 9/23/2013 11:59:99pm

-----------------------------------------

If today is Wednesday 9/11/2013 return:

Tuesday 9/10/2013 and Monday 9/16/2013 11:59:99pm

-----------------------------------------

If today is Friday 9/27/2013 return:

Tuesday 9/24/2013 and Monday 9/30/2013 11:59:99pm


Can anyone lend their expertise? I have tried myself and I struggle with having it default to Tuesday or Monday if it happens to be that day of the week... 

Kind Regards,

-c

 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>