I need to create a query that will insert record but date should be either 1st or the 3rd tuesday of each month, what code should i use.
Printable View
I need to create a query that will insert record but date should be either 1st or the 3rd tuesday of each month, what code should i use.
or you can just give me code for third Tuesday of each month.
Here is a solution:
SELECT @ResultDate = DATEADD(wk, DATEDIFF(wk,0, dateadd(dd, 18 - datepart(day,getdate()),getdate()) ), 1);
this will return me Tuesday of a specific month( in this case its system date) and if i use while loop with dateadd function i can get the result.
I hope it will help others.