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
 General SQL Server Forums
 New to SQL Server Programming
 Filtering on dates

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2010-02-12 : 09:10:00
Why doesn't this work ? No records are returned. the connection string works because if I remove the filter all records are returned. The code is in a vs console application

myCommand = New SqlCommand("Select * from tblSS_Cases WHERE SS_RemindMe = " + Today(), myConnection)

There are records there with this in SS_RemindMe field

12/02/2010 00:00:00

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-02-12 : 09:14:42
Today() is not an MS SQL server command. Also, that would give you minutes, so you need to strip those off.
This removes the time piece in sql server
SELECT dateadd(day,datediff(day,0,getdate()),0)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-12 : 09:17:19
What is the output of Today() and what data type is SS_RemindMe?
Sample values?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2010-02-12 : 09:18:23
Thank you but I am running this in VB and when I enter your code day and getdate are underlined in blue
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2010-02-12 : 09:20:22
CA_Remindme is datetime. Today is, well - today. I am in the Uk so dates are dd/mm/yyyy
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-12 : 09:21:05
Include it within the command..like..
myCommand = New SqlCommand("Select * from tblSS_Cases WHERE SS_RemindMe = dateadd(day,datediff(day,0,getdate()),0)" , myConnection)

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-12 : 09:23:48
quote:
Originally posted by Pinto

CA_Remindme is datetime. Today is, well - today. I am in the Uk so dates are dd/mm/yyyy


wherever you're dates are stored in sql table as integer values internally and always displayed in ccyy-mm-dd hh:mi:ss format. you dont have to be worried about format in which you store dates as you can always retrieve it in format you want using formatting functions at front end

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2010-02-12 : 09:24:56
Thank you vijayisonly - I was trying to assign it to a variable in my code. It now works
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-12 : 09:58:28
You're welcome.
Go to Top of Page
   

- Advertisement -