Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

SQL Server - Get Date or Time From Date Time Column / Field in SQL Server 2008 / 2005

Sep 4, 2013
Introduction

Here I will explain SQL Server query to get only date or time from date time field in SQL Server2008 or 2005 or how to get only date or time from current date time field in SQL Server 2008 / 2005.

Description

In previous articles I explained sql server get list of procedures which contains table name, SQL Server difference between view and stored procedure, SQL Server difference b/w LEN and DATALENGTH functions and many articles relating to SQL Server. Now I will explain how to get only date or time from date time field in SQL Server.

We can get date or time in different formats from date time field using different styles. Now I will display different format of dates with samples check it 


DECLARE @DateTime DATETIME
 SELECT @DateTime = '2010/05/20 11:21:13'

/*For mm/dd/yyyy format*/
Select CONVERT(VARCHAR(10),@DateTime ,101) as Date


/*For yyyy.mm.dd format*/
Select CONVERT(VARCHAR(10),@DateTime ,102) as Date


/*For dd/mm/yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,103) AS Date


/*For dd.mm.yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,104) AS Date


/*For dd-mm-yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,105) AS Date


/*For hh:mi:ss format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,108) AS Date


/*For mm-dd-yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,110) AS Date


/*For yyyy/mm/dd format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,111) AS Date


/*For yyyymmdd format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,112) AS Date



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Irtekaz Ahmed Khan said...

Thanks

Gaurav Sancheti said...

Working properly
Thanks

Unknown said...

This is a very good site I've come across,
Thank you Suresh Sir.......

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.