Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-25
4
Medium Priority
?
329 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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