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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -