Monday, July 30, 2012

find day,month,year from date in sql server

Find Day, Month and Year values from Date of Birth or any other date stored in table with DateTime Column type

Suppose Dob is the column in Employee table for storing date of birth of all employee.
Query to find out month value from given Date of Birth:
SELECT EmployeeName, DATEPART(M,Dob) FROM Employee

Sql Query to find out Day value from Employee date of birth
SELECT EmployeeName, DATEPART(D,Dob) FROM Employee

Find out total no of employees born this month
SELECT COUNT(1) FROM Employee WHERE DATEPART(M,Dob)= DATEPART(M,GETUTCDATE())

UTC:Cordinated Universal Time[International Time]
GETUTCDATE()

IST:Indian standerd Time[Indian Time]
DECLARE @ISTdate DATETIME
SELECT @ISTdate=DATEADD(minute,330,GETUTCDATE())


0 comments:

 
Powered by Code Imagine