Introduction:
Here I will explain how to add hours to current date using DateAdd function in sql server with example or adding hours or minutes to date in sql server. By using DateAdd function in sql server we can add hours or minutes to current date in sql server.
Here I will explain how to add hours to current date using DateAdd function in sql server with example or adding hours or minutes to date in sql server. By using DateAdd function in sql server we can add hours or minutes to current date in sql server.
Description:
In
previous articles I explained SQL Server get only hours, minutes, date and time from datetime, take database backup in sql server, encrypt and decrypt string in sql server, sql server interview questions for experienced, cursor example in sql server and many articles relating to SQL
server.
Now I will explain how to add hours or minutes to current date in sql
server.
Add Hours to Date in SQL
declare @hours int;
set @hours = 5;
select getdate() as currenttime, dateadd(HOUR, @hours, getdate()) as timeadded
|
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
Add Minutes to Date in SQL
To
add minutes to date field 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
|
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. |
|||
|
|||
1 comments :
Hi Suresh,
I need Query as Day wise date function. Please help.
Note: Only a member of this blog may post a comment.