Solved

MS SQL SERVER  get countdown

Posted on 2011-02-25
4
321 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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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