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)
 difference between 2 varchar

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-01-15 : 09:16:27
i have 2 fiels like :

a varchar 8
b varchar 8

  a           b
22/12/08 28/12/08


how can i know the number of hours between a and b?

thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-15 : 09:24:57
Use DATEDIFF function.
Here is an explanation of how DATEDIFF works http://www.sqlteam.com/article/datediff-function-demystified.



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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-15 : 09:29:03
quote:
Originally posted by inbs

i have 2 fiels like :

a varchar 8
b varchar 8

  a           b
22/12/08 28/12/08


how can i know the number of hours between a and b?

thanks



why are you storing dates in varchar field?
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-01-15 : 09:38:03
cause i get them from source as varchar

and how i can do it for time?
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-15 : 10:49:38
quote:
Originally posted by inbs

cause i get them from source as varchar

and how i can do it for time?



Just because your source is varchar doesn't mean your column should be of the same type. As long as your data is a valid date, you can pass it to a datetime column.
Go to Top of Page
   

- Advertisement -