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 Only Hours, Minutes, Date, Time from DateTime Field

Jun 3, 2015
Introduction:

Here I will explain how to get only hours and minutes from datetime in
sql server or extract / get only time from datetime field in sql server or get hours datetime in sql server  or get only minutes from sql server or query to get only date / time / hours / minutes from sql server.
Description:

Get Only Date from Datetime Field in SQL

To get only date from datetime field in sql server we need to write the query like as shown below


Select CONVERT(VARCHAR(10),GETDATE(),101) OnlyDate

When we run above query we will get output like as shown below

Output


Get Only Date from Datetime Field in SQL

If you want to get date in different formats like dd/mm/yyyy or dd-mm-yyyy or etc… check this article Change SQL Get only date from datetime in different formats

Get Only Time from Datetime Field in SQL

To get only time from datetime field in sql server we need to write the query like as shown below


SELECT CONVERT(VARCHAR(5),getdate(),108) OnlyTime

When we run above query we will get output like as shown below

Output


Get Only Time from Datetime Field in SQL

Get Only Hours from Datetime Field in SQL

To get only hours from datetime field in sql server we need to write the query like as shown below


SELECT DATEPART(hour, GETDATE()) AS OnlyHours

When we run above query we will get output like as shown below

Output


Get Only Hours from Datetime Field in SQL

Get Only Minutes from Datetime Field in SQL

To get only minutes from datetime field in sql server we need to write the query like as shown below


SELECT DATEPART(minute, GETDATE()) AS OnlyMinutes

When we run above query we will get output like as shown below

Output


Get Only Minutes from Datetime Field in SQL

I hope it helps you….

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

0 comments :

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.