.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Split Year ,Month ,Day from DATETIME

Posted By:Narayanan       Posted Date: May 09, 2013    Points: 40    Category: SQL Query    URL: http://www.dotnetspark.com  

Today we will see the How to Split Year,Month ,day from DateTime Column in SQL
 

Here is query

   You can achieve this task in two ways.

1) DATEPART
2) Year,Mont,Day

Let's see the Query:
Split Year,Month and Day from DateTime Column in SQL Server

1 ) Select DATEPART(YEAR,ColName) as [Year],DATEPART(Month,ColName) as [Month],DATEPART(Day,ColName) as date fromtbl_Name where ColName!=''

2) Select YEAR(ColName) as [Year],Month(ColName) as [Month],Day(ColName) as date from tbl_Name  where ColName !=''


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend