SQLTeam.com | Weblogs | Forums

Help with Date Arithmetic

I have some code in SAS that I need to rewrite which is trying to bring in a column called Last Opp Date (changed name to Last Opp Display) based conditions involving today's date. Could someone tell me how to write this while also bringing it in as a UK Date format (ddmmyyy) instead of the yyymmyy it's in now?

case when Last_opp_date = . then ''
when Last_opp_date < today() then 'Breached'
when Last_opp_date > today()+13 then '>14 Days'
else put(( Last_opp_date ),date9.) end
as Last_opp_Display,

Also, I need the Last Opp Date column to make a new column called Last Opp Week which is based on the below code:

case when Last_Opp_Date = . then ''
when ( Last_Opp_Date - today()+1) lt 1 then 'Breached'
when weekday(Last_opp_Date) = 1 then put(intnx('day',Last_Opp_Date,-6),date9.)
else put(( intnx('week', Last_Opp_date,0,'b')+1),date9.) end
as Last_Opp_Week,

Barely understand what this one is saying but again, this needs to come in as the first date of the month as ddmmyyy and also have the correct conditions applied.

These are both within the initial Select function (if that's the right way to do it)

Hopefully this makes sense and someone can help me to write this for SQL server! Thanks so much!