Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have stored employee job joining records,and also stored joining date(dd/mm/yyyy) in table here.
now i want search employee by joining months and week.
how i do this?
Posted

check this example
SQL
DECLARE @Date Datetime= getdate()
SELECT 
  @Date Supplied_Date 
, month(@Date) Month_Number
, datename(month,@Date) Month_Name
, datepart(week,@Date) Week_Of_Year
, datediff(week, dateadd(week, datediff(week, 0, dateadd(month, datediff(month, 0, @date), 0)), 0), @date - 1) + 1 Week_Of_Month

Happy Coding!
:)
 
Share this answer
 
Comments
Avadhesh yadav 30-Dec-13 23:41pm    
Thanks Peter & Aarti
Aarti Meswania 31-Dec-13 0:50am    
welcome!
Glad to help you! :)
Assuming there are a 'joindate' and 'empname' in the table called 'employee'. To find employees that join either in December or on the 24th week of the year, try this:
SELECT empname FROM employee WHERE DATEPART(MONTH, joindate) = '12' OR DATEPART(WEEK, joindate) = '24'

You should change the 'OR' to 'AND' if you want both conditions to be met at the same time.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900