DateTime Queries

D

Dave

Hi,

Whats the best way of handling dates gathered from the OS (e.g. using
DateTime.Now or SqlDateTime) and using it in a SQL query? I want to create
a culture neutral string so that a SQL server will process the date no
matter of the language or database settings.

Overloading DateTime.ToString with "s" seems to produce a date that SQL
processes regardless of the original date format or OS settings, but there
is no equivalant overload with SqlDateTime.

How do most people handle this and avoid the error "Syntax error converting
datetime from character string"?

Thanks.
 
P

Paul Clement

¤ Hi,
¤
¤ Whats the best way of handling dates gathered from the OS (e.g. using
¤ DateTime.Now or SqlDateTime) and using it in a SQL query? I want to create
¤ a culture neutral string so that a SQL server will process the date no
¤ matter of the language or database settings.
¤
¤ Overloading DateTime.ToString with "s" seems to produce a date that SQL
¤ processes regardless of the original date format or OS settings, but there
¤ is no equivalant overload with SqlDateTime.
¤
¤ How do most people handle this and avoid the error "Syntax error converting
¤ datetime from character string"?

Are you using a stored procedure with parameters?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
D

Dave

Paul Clement said:
¤ Hi,
¤
¤ Whats the best way of handling dates gathered from the OS (e.g. using
¤ DateTime.Now or SqlDateTime) and using it in a SQL query? I want to
create
¤ a culture neutral string so that a SQL server will process the date no
¤ matter of the language or database settings.
¤
¤ Overloading DateTime.ToString with "s" seems to produce a date that SQL
¤ processes regardless of the original date format or OS settings, but
there
¤ is no equivalant overload with SqlDateTime.
¤
¤ How do most people handle this and avoid the error "Syntax error
converting
¤ datetime from character string"?

Are you using a stored procedure with parameters?


Paul
~~~~
Microsoft MVP (Visual Basic)

No, just using a SqlDataAdapter and doing SQL queries directly.....
 
P

Paul Clement

¤
¤ ¤ >
¤ > ¤ Hi,
¤ > ¤
¤ > ¤ Whats the best way of handling dates gathered from the OS (e.g. using
¤ > ¤ DateTime.Now or SqlDateTime) and using it in a SQL query? I want to
¤ > create
¤ > ¤ a culture neutral string so that a SQL server will process the date no
¤ > ¤ matter of the language or database settings.
¤ > ¤
¤ > ¤ Overloading DateTime.ToString with "s" seems to produce a date that SQL
¤ > ¤ processes regardless of the original date format or OS settings, but
¤ > there
¤ > ¤ is no equivalant overload with SqlDateTime.
¤ > ¤
¤ > ¤ How do most people handle this and avoid the error "Syntax error
¤ > converting
¤ > ¤ datetime from character string"?
¤ >
¤ > Are you using a stored procedure with parameters?
¤ >
¤ >
¤ > Paul
¤ > ~~~~
¤ > Microsoft MVP (Visual Basic)
¤
¤ No, just using a SqlDataAdapter and doing SQL queries directly.....
¤

Then you're pretty much at the mercy of the database implementation. It's much easier to work with
dates in their native format than converting from a string value.


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top