From my database I am trying to fetch all records after a particular date. For this I am using the query
SELECT *
FROM Events_tbl
WHERE lastupdated > '07-18-2011' and Venue=8
This particular piece of code is working in my localhost. But when I upload to server it is not returning anything. Could someone help please?
I am really stuck.
In my SQL Server database the datetime value is
2011-07-19 19:37:50.727
I am using pipeten server in UK. I am working on asp.net c#
Thanks
I suggest you don't use a text format for your query in the first place - use a parameterized query and specify the parameter value as a DateTime. That way you don't need to worry about formatting at all, and you keep your code away from your data.
There's no reason for you to perform a conversion either to or from text here - so don't. Keep the values in their most appropriate data type.
(This goes for all data values, by the way - and parameterized queries also help to protect you from SQL injection attacks.)
use the ISO dateformat (YYYYMMDD) it is safe across all languages
SELECT * from Events_tbl where lastupdated > '20110718' and Venue=8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With