sql server - How to get Day and Month from Date Sql Query? -


date format : 20-jun-14

need query return : 20-jun

current date : 20-jun-2015

so,that should compare current date , return in above case

total years : 1 year

you can cut of parts of date using datepart.

see:

select datepart(day,currentdate), datepart(month, currentdate) 

this way should able compare dates example in where-clause.

as questioner need date not integer, use datename function:

select datepart(day,currentdate), datename(month, currentdate) 

due fact datename doesn't support mmm format, use case structure.

select datepart(day,currentdate) day,       case datepart(month, currentdate)           when 1 n'jan'           when 2 n'feb'           when 3 n'mar'           when 4 n'apr'           when 5 n'mai'           when 6 n'jun'           when 7 n'jul'           when 8 n'aug'           when 9 n'sep'           when 10 n'oct'           when 11 n'nov'           when 12 n'dec'       end month 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -