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.
| Author |
Topic |
|
ECML_David
Starting Member
2 Posts |
Posted - 2012-03-01 : 10:07:23
|
| Hi All,First post so thanks for having me :)i have a database that is holding dates in VARCHAR in the format: 16/08/2010 10:31:22I want to be able to select all records that have been created today but I'm stuggling to get my head around converting the VARCHAR then running the SELECT statment against it. I dont want to alter all the records just convert them for the purpose of the SELECTAny help very gratefuly recieved:select * from opencall where(convert(datetime,logdate,101)) < GETDATE() |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-03-01 : 10:20:12
|
try 103 instead of 101 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
ECML_David
Starting Member
2 Posts |
Posted - 2012-03-01 : 10:43:48
|
| OK so this seems to work beter:select * from opencall DATEDIFF(dd,GetDate(),CONVERT(datetime,logdate,103)) = 0however i get the message:"dd" is not a recognized table hints option. If it is intended as a parameter to a table-valued function ensure that your database mode is set to compatabilty 90server is SQL 2005 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-01 : 10:59:42
|
quote: Originally posted by ECML_David Hi All,First post so thanks for having me :)i have a database that is holding dates in VARCHAR in the format: 16/08/2010 10:31:22I want to be able to select all records that have been created today but I'm stuggling to get my head around converting the VARCHAR then running the SELECT statment against it. I dont want to alter all the records just convert them for the purpose of the SELECTAny help very gratefuly recieved:select * from opencall where(convert(datetime,logdate,101)) < GETDATE()
By doing so you're really making it hard for yourself. Always try to use proper datatype for fields. Storing date values as varchar will really make date manipulations difficult and also causes problems if you're storing dates in varying formats------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|