Avatar of dynamicweb09
dynamicweb09Flag for India

asked on 

Sql server 2005

How can I difference two date time and show like this "5 houres ago" or "10 minute ago" ?


suppose i have two datetime like

Start Date = 2010-01-22 15:29:55.090
End time =  2010-01-22 16:30:09.153

and I want to show "1 minute ago" format.
               
                   OR
Start Date = 2010-01-22 15:29:55.090
End time =  2010-01-24 16:30:09.153

and I want to show "2 daya ago" format.
PHPMicrosoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
dynamicweb09
Avatar of PortletPaul
PortletPaul
Flag of Australia image

the building blocks of this would include:

datediff(day,startDate,endDate)
datediff(hour,startDate,endDate)
datediff(minute,startDate,endDate)

What happens after '59 minutes ago'?
for example, 78 minutes, how is this to be displayed?
or, 27 hours?

I'd suggest some more definition of the requirement may be required
SOLUTION
Avatar of Om Prakash
Om Prakash
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dynamicweb09
dynamicweb09
Flag of India image

ASKER

I used this .but still its not working

declare @DateValue datetime
select @DateValue ='2013-05-14 15:29:55.090'

SELECT  CASE
          WHEN @DateValue-GETDATE() >= 1 THEN CAST(DATEPART(dy, @DateValue-GETDATE()) AS varchar) + ' day(s) remaining'
          WHEN @DateValue-GETDATE() >= 0 THEN CAST(DATEPART(hh, @DateValue-GETDATE()) AS varchar) + ' hour(s) remaining'
          /*Note, it's convenient to switch around for negatives*/
          WHEN GETDATE()-@DateValue <= '00:59' THEN CAST(DATEPART(mi, GETDATE()-@DateValue) AS varchar) + ' minutes(s) overdue'
          WHEN GETDATE()-@DateValue <= 1 THEN CAST(DATEPART(hh, GETDATE()-@DateValue) AS varchar) + ' hours(s) overdue'
        ELSE
          CONVERT(varchar, @DateValue-GETDATE(), 121)
        END AS Time_Scale
SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of dynamicweb09
dynamicweb09
Flag of India image

ASKER

Thanks All............
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo