Solved

countdown till day of the week...mssql server 2005

Posted on 2011-02-25
4
319 Views
Last Modified: 2012-05-11
If I have a curr_date...how do I subtract a future date

so that it would return '3 days: 15hours: 24 seconds"

so if tday is Friday feb 22, 2011...and the next process date is tomorrow sat at noon..

'1 day: 2 hours: 34 seconds'
0
Comment
Question by:GlobaLevel
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
rocky_lotus_newbie earned 500 total points
Comment Utility
DECLARE @Startdate DATETIME, @Enddate DATETIME
SET @Startdate = '2011-01-02 11:35:26'
SET @Enddate = '2011-01-06 03:15:31'

-- Query by SqlServerCurry.com
-- Total seconds in a day
DECLARE @TotalSec int
SET @TotalSec = 24*60*60;

-- Convert DateDiff into seconds
DECLARE @DiffSecs int
SET @DiffSecs = DATEDIFF(SECOND, @Startdate, @Enddate)

SELECT
CONVERT(char(2), (@DiffSecs/@TotalSec))as [Days],
CONVERT(char(2), ((@DiffSecs%@TotalSec)/3600)) as [Hours],
CONVERT(char(2), (((@DiffSecs%@TotalSec)%3600)/60)) as [Minutes],
CONVERT(char(2), (((@DiffSecs%@TotalSec)%3600)%60)) as [Seconds]

Link: http://www.sqlservercurry.com/2011/01/date-difference-in-sql-server-in-days.html
0
 
LVL 24

Expert Comment

by:mankowitz
Comment Utility
Use the TIMEDIFF function. In order to determine the time between now and feb 25, 2011 at 1:15:23 AM, you'd use

select timediff(now(), 20110225011523)
0
 
LVL 10

Author Comment

by:GlobaLevel
Comment Utility
rocky...

great code....

just trying to mod yours into the below...

DECLARE @NEXT_DELIVERY_DATE NVARCHAR(MAX)
--
SET @NEXT_DELIVERY_DATE = 'SCHEDULED FOR THIS ' + @ACTUAL_DAY + ' : ' + @DAYS + ' Days ' + @HOURS + ' Hours' +
@MIN + ' Mins ' + @SEC + ' Secs LEFT TILL LAUNCH'
0
 
LVL 10

Author Comment

by:GlobaLevel
Comment Utility
got it...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

9 Experts available now in Live!

Get 1:1 Help Now