Wednesday 26 February 2014

How to find out day and year and month in respective date in sql server .2005 | sql server 2008.

How to find out day and year and month in respective date in sql server .2005 | sql server 2008.

we will see how can we find out day and month and year in given date separately .
to find out same we have to use DAY ,MONTH and YEAR keyword respectively which is by default or defined by sql server .
so no need to put some extra efforts.
just write same keyword after you use that keyword they will appear in pink colour in sql server.
lets look at examples.
suppose i have last date of submission my fee now i want to find  out day and month and year of lastdateofsubmission then i will
write like this.

for  day select DAY(LastSubmissionDate) from tableName
for month select MONTH(LastSubmissionDate) from tableName
for year  select Year(LastSubmissionDate) from tableName


now output will be
31 --day
2  --month
2014 --year


we can write in same line also..
select   DAY((LastSubmissionDate) ),MONTH ((LastSubmissionDate) ),YEAR ((LastSubmissionDate)  ) from tableNamewhere DueDate <> '' and DAY((LastSubmissionDate) ) in ('1','13','30')
which will gives you date which comes under day 1 , 13, 30 in every month and year.