Comparing dates
-
Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.
Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )
-
Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.
Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )
You should not use string concatenation since it opens you up to sql injection attacks. Use parameterized queries instead.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.
Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )
I'm not sure if this will work - give it a go anwyay:
"Select * from Table1 where birth > cast(""" + d1.toString() + """as datetime) And birth <= cast(""" + d2.toString()+""" as datetime)"
Regards GuyYou always pass failure on the way to success.
-
You should not use string concatenation since it opens you up to sql injection attacks. Use parameterized queries instead.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Paul Conrad wrote:
You should not use string concatenation since it opens you up to sql injection attacks.
Hi there Paul, Please explain your statement. Thanks in advance. Danny
-
Paul Conrad wrote:
You should not use string concatenation since it opens you up to sql injection attacks.
Hi there Paul, Please explain your statement. Thanks in advance. Danny
Read this article, http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
Read this article, http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
Thanks man. Good info. Danny