PC Review


Reply
Thread Tools Rate Thread

DateTime Queries

 
 
Dave
Guest
Posts: n/a
 
      30th Jun 2005
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.


 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      1st Jul 2005
On Thu, 30 Jun 2005 18:53:27 GMT, "Dave" <(E-Mail Removed)> wrote:

¤ 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)
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      1st Jul 2005

"Paul Clement" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Thu, 30 Jun 2005 18:53:27 GMT, "Dave" <(E-Mail Removed)> wrote:
>
> ¤ 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.....


 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      5th Jul 2005
On Fri, 01 Jul 2005 14:26:37 GMT, "Dave" <(E-Mail Removed)> wrote:

¤
¤ "Paul Clement" <(E-Mail Removed)> wrote in message
¤ news:(E-Mail Removed)...
¤ > On Thu, 30 Jun 2005 18:53:27 GMT, "Dave" <(E-Mail Removed)> wrote:
¤ >
¤ > ¤ 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)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Millisecond values missing when inserting datetime into datetime column of sql Server Manikandan Microsoft C# .NET 4 18th Jul 2007 08:59 PM
How can I save a DateTime from my C# program into a SQL Server (datetime) database column. Steve Kershaw Microsoft ASP .NET 5 29th Aug 2006 03:10 AM
converting Unix datetime count to .Net DateTime object Mark Worrall Microsoft Dot NET Framework 2 13th Feb 2004 05:52 PM
Re: converting Unix datetime count to .Net DateTime object Mark Worrall Microsoft C# .NET 1 4th Feb 2004 07:29 AM
XML dateTime conversion to DateTime.MinValue accross timezones Symon R Microsoft Dot NET 0 6th Aug 2003 07:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:57 AM.