Lina Armiento
Lina Armiento

Reputation: 13

difference in days between two dates

I am very new at this. I need in a seperate column in this query to have the difference in days between t.1start and t1.finish.

Thanks ,Louie

SELECT ROW_NUMBER() OVER(ORDER BY TOWN) AS 'row', 
T1.Surname,
T1.Forename,
T1.Town,
T1.Description,
T1.Sex,
T1.DOB,
T1.start,
T1.finish,
FROM dbo.viewServiceContractFull T1 
WHERE
T1.finish>='2013/01/01'
and 
T1.finish<='2013/01/31'

How do I now get only certain towns to come up in query?

Upvotes: 1

Views: 218

Answers (3)

CloudyMarble
CloudyMarble

Reputation: 37566

You can use the DATEDIFF function to determine the intervall between two dates, you can use the CAST/CONVERT to transform your string dates into real dates if needed, like:

CAST('2010-01-22 15:29:55.090' AS DATETIME)

The CONVERT function enables you to choose the format of the date.

Upvotes: 0

Black Cloud
Black Cloud

Reputation: 481

In SQL Server you can use

SELECT DATEDIFF (MyUnits, '2010-01-22 15:29:55.090', '2010-01-22 15:30:09.153')

Upvotes: 1

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67197

SELECT ROW_NUMBER() OVER(ORDER BY TOWN) AS 'row', 
T1.Surname,
T1.Forename,
T1.Town,
T1.Description,
T1.Sex,
T1.DOB,
T1.start,
T1.finish, cast(DATEDIFF(DAY,T1.start,T1.finish) as varchar) as difference
FROM dbo.viewServiceContractFull T1 
WHERE
T1.finish>='2013/01/01'
and 
T1.finish<='2013/01/31'

Additionally have a look at this

Upvotes: 0

Related Questions