Solved

MS SQL SERVER  get countdown

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Detach & Attach 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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

22 Experts available now in Live!

Get 1:1 Help Now