[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

How to Compare .NET Date with MSSQL DateTime?

Christine

1/15/2003 12:07:00 PM

I have a string (e.g.1/15/2003 5:40:45 PM) which I would
like to compare with a datetime column in my database.

I find that I cannot simply concat it in a SQL Statement
(e.g. "SELECT * FROM TABLE WHERE Date='" & strDate & "'"),
as it don't return me any row. The date and time format is
the same as my database. I've also tried other methods
such as CONVERT.

I would like to know how I can compare a .NET DATE
variable with MSSQL DateTime.

Any help is appreciated, thanks in advance.
1 Answer

Patrice Scribe

1/15/2003 5:39:00 PM

0

IMO the best option is to convert as soon as possible your "text" date to a
"true" date and use then a date parameter.

If you prefer to pass the date as a string (as this is inside your SQL
statement), you could use the ISO format that works regardless of SQL
Server settings :

SELECT * FROM MyTable WHERE d='20030115 05:40:45PM'

"christine" <christine72@hotmail.com> a écrit dans le message de news:
61cd01c2bc86$545d37b0$89f82ecf@TK2MSFTNGXA01...
> I have a string (e.g.1/15/2003 5:40:45 PM) which I would
> like to compare with a datetime column in my database.
>
> I find that I cannot simply concat it in a SQL Statement
> (e.g. "SELECT * FROM TABLE WHERE Date='" & strDate & "'"),
> as it don't return me any row. The date and time format is
> the same as my database. I've also tried other methods
> such as CONVERT.
>
> I would like to know how I can compare a .NET DATE
> variable with MSSQL DateTime.
>
> Any help is appreciated, thanks in advance.