Solved

MS SQL SERVER  get countdown

Posted on 2011-02-25
4
332 Views
Last Modified: 2012-05-11
So whenever the user presses a button, it runs a sproc ... i need to return a value of current_date- top of the hour...so for example...if the user presses the submit at 1:31

Then it would return "29"..because its 29 minutes till 2:00
Next_delevery_date_go_hour = (top of the hour) - (currdate) .....

 DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
-- i may not have this right...

--round it up...
 DECLARE @round_up_DATE smalldatetime
 SET  @round_up_DATE = ISNULL@round_up_DATE, getDATE())

declare @countdown nvarchar(10)
set  @countdown  = @round_up_DATE  - @CURR_DATE

--- i know this is off ....
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:rocky_lotus_newbie
ID: 34982169
select (60-RIGHT(convert(varchar(5),getdate(),114),2))

This gives the number of minutes left till the next hour.

For Example, If you run this at 1.28 PM, it returns 32.

Thanks,
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34982440
Alternatively:

SELECT 60 - DATEPART(MINUTE,GETDATE())


0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34982539
Here is the complete code.  It also correctly returns '0' at the hour (1:00 PM, returns 0).

DECLARE @COUNTDOWN NVARCHAR(10)

SET @COUNTDOWN = 60 - DATEPART(MINUTE,GETDATE())

IF @COUNTDOWN = '60' SET @COUNTDOWN = 0

Open in new window

0
 
LVL 17

Accepted Solution

by:
dbaSQL earned 500 total points
ID: 34982553
Here you go:

DECLARE @pressbutton DATETIME = '2011-02-25 13:31:00.000'
DECLARE @topofhour DATETIME = DATEADD(mi, ROUND(DATEDIFF(mi, 0, @pressbutton) / 60.0, 0) * 60,0)

SELECT @pressbutton
SELECT @topofhour
SELECT DATEDIFF(mi,@pressbutton,@topofhour)
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question