Link to home
Start Free TrialLog in
Avatar of VKugel
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),CreatedDate, 101) = '" & DateTime.Parse(Now()).ToString("m/d/yyyy") & "'"

Any help would be appreciated.
Regards,
Avatar of tigin44
tigin44
Flag of Türkiye image


use this

 s = "Select * From Leads Where CreatedDate = '" & Now() & "'";
Avatar of VKugel
VKugel

ASKER


That does not work. That was my first try. I tried it again with no luck.
what is the error message you get?
Avatar of VKugel

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.
ASKER CERTIFIED SOLUTION
Avatar of VKugel
VKugel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anthony Perkins
>>"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.