Solved

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

Posted on 2011-02-25
4
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
rocky_lotus_newbie earned 500 total points
ID: 34982652
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
ID: 34982726
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
ID: 34983149
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
ID: 34983286
got it...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

718 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