VKugel
asked on
Select records DateTime field that match todays date
I have a VB.net application that uses SQL server 2005. When I created new records in my application I save todays date in a date time field using Now(). When I try and slected records that were created today"m/d/yyyy" I can not get any records.
I am using SQLClient for my database connection.
This is my selection statment:
"Select * From Leads Where CONVERT(VARCHAR(20),Create dDate, 101) = '" & DateTime.Parse(Now()).ToSt ring("m/d/ yyyy") & "'"
Any help would be appreciated.
Regards,
I am using SQLClient for my database connection.
This is my selection statment:
"Select * From Leads Where CONVERT(VARCHAR(20),Create
Any help would be appreciated.
Regards,
ASKER
That does not work. That was my first try. I tried it again with no luck.
what is the error message you get?
ASKER
I don't get an error message. I don't get any records.
My current Created date records are dated 1/31/2010 9:00:58 AM
If I use Now(), it will not match bacause the times do not match.
My current Created date records are dated 1/31/2010 9:00:58 AM
If I use Now(), it will not match bacause the times do not match.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>"Select * from Leads where datediff(day, CreatedDate, getdate())=0"<<
Unless you only have a few thousand rows, than that is a very bad idea as it is not scalable. MS SQL Server will not be able to take advantage of any index on the table.
Let us know if you want to do it right.
Unless you only have a few thousand rows, than that is a very bad idea as it is not scalable. MS SQL Server will not be able to take advantage of any index on the table.
Let us know if you want to do it right.
use this
s = "Select * From Leads Where CreatedDate = '" & Now() & "'";