Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Time query

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-06-12 : 07:08:05
Hi,

I have 1 date field where im interested in the time.
i.e. 2009-01-01 17:30:00.000

The query I need to write is as follows

case when (convert(varchar, datefield1, 108) > '17:00:00') THEN
datefield1 - '2009-01-01 17:00:00.000'

But I get error operand error converting character string for substract function.

I basically want if the time is after 5, get the difference in time between the field and 5pm.

Thanks
C

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-12 : 07:13:14
case when (convert(varchar(8), datefield1, 108) > '17:00:00') THEN DATEDIFF(MINUTE, '2009-01-01 17:00', datefield1)


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-06-12 : 07:46:57
hi,

Thanks for the prompt reply, how would I be able to get the minute count from time?

Minute(datetime1)???

quote:
Originally posted by Peso

case when (convert(varchar(8), datefield1, 108) > '17:00:00') THEN DATEDIFF(MINUTE, '2009-01-01 17:00', datefield1)


E 12°55'05.63"
N 56°04'39.26"


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-12 : 08:50:53
The

1. Absolute minute value? 17:45 -> 45
2. Number of minutes since last minute? 17:45 -> 1065



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -