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

how to calculate givendate is before last sunday of the month or after the last sunday of the month

$
0
0

in my sql below i am calculating next moday,

here in below i passed 7/11/2011 which is monday it will returns 07/18/2011 which is next monday
select  DaTEADD([day], ((DATEDIFF([day], '19000101', convert (datetime, '07/11/2011')) / 7) * 7) + 7, '19000101')


here in below i passed 7/10/2011 which is Sunday it will returns 07/11/2011 which is next monday
select  DaTEADD([day], ((DATEDIFF([day], '19000101', convert (datetime, '07/10/2011')) / 7) * 7) + 7, '19000101')

so now the piece i am trying is

if the given date is on or before last sunday of the month then it is just the given day itself

if it is falls after last sunday of the month then it shoud calculate to next monday(which is the above query, which calculates next monday)


i did several trys could somebody please assist me

please sir,

thanks a ton in advance

appreciate your help

asitti


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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