Solved

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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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