Solved

MS SQL SERVER  get countdown

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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