Solved

MS SQL SERVER  get countdown

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updating ms sql with special characters 8 39
Table create permissions on SQL Server 2005 9 40
sql query Help 12 52
Query Peformance + mulitple query plans 9 47
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now