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.
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:
In
previous articles I explained joins in sql server, function example in sql server 2008, Primary key constraint in sql
server,
foreign key constraint in sql
server,
query to remove first and last
characters from string in sql server, Pass XML file as parameter from C#
to SQL stored procedure, cursor example in sql server and many articles relating to SQL
server.
Now I will explain how to get only date / time / hours / minutes from datetime
field in sql
server.
Get Only Date from Datetime Field in
SQL
Select CONVERT(VARCHAR(10),GETDATE(),101) OnlyDate
|
When we run above query we will get output like as
shown below
Output
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
SELECT CONVERT(VARCHAR(5),getdate(),108) OnlyTime
|
When we run above query we will get output like as
shown below
Output
Get Only Hours from Datetime Field in
SQL
SELECT DATEPART(hour, GETDATE()) AS OnlyHours
|
When we run above query we will get output like as
shown below
Output
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
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. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.