Re: converting string to datetime

Tech-Archive recommends: Speed Up your PC by fixing your registry



Or even why to return a string at all ? My personal preference would be to
always return a date from SQL Server. Then the date is formatted client side
for display (what if you display those data in a grid and want to sort them
by date ?)

--
Patrice

"(O)enone" <oenone@xxxxxxxxxxx> a écrit dans le message de news:
UyX9j.12127$ov2.7141@xxxxxxxxxxxxxxxxxxxxxxx
zino wrote:
I need to convert a string as: "DEC 18 2007 2:49:40:783PM"
to a date. This value is sent by SQL server as :select
convert(varchar(30), creationDate, 109) from ... ... .

Just one question: why don't you get SQL Server to return the date in
ISO8601 format instead? This is the only globally identifiable
non-ambiguous format in which dates can be represented as strings.

You can get SQL Server to return it in this format by changing the 109 in
your convert statement to 21 instead. (I <3 magic numbers....)

Then you can just use DateTime.Parse or CDate to convert the string to a
date.

HTH?

--

(O)enone



.



Relevant Pages

  • Re: Moving a VBA function to SQL server
    ... "String Functions " in Books Online. ... The SQL server database contains a table named 'WorkOrders'. ... This will produce a job header formatted like this: ... The format he specifies is stored in table 'Settings' - field 'JobHdrMask' ...
    (comp.databases.ms-access)
  • Re: The third time to ask in here ... Mobile Web form
    ... You would be better directing sql server questions to the ... > i can't change its format, ... > format in the DB to string or the string that the user ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Undocumented CONVERT styles
    ... The string value will not be interpreted ... independently of the date format: ... SQL Server changes this to something else when you add it ...
    (microsoft.public.sqlserver.programming)
  • Re: Linking tables access - sql server 2005
    ... Another advantage of this method is that you don't need an ODBC setting on the local computer, ... Create a linked table to SQL Server without using a DSN ... Name of the table that you are linking to on the SQL Server database ... Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Format a datetime columns output?
    ... you could convert the date to a string? ... SQL Server you should use the format YYYYMMDD, ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)