Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple DateTime conversion (XML to SQL)

Status
Not open for further replies.

SiJP

Programmer
May 8, 2002
708
GB
I need to convert a string datetime "2006-03-16T17:12:36.328" (which is sourced from an XML document), into a string that is acceptable to be used in a SQL insert statement.

(i.e '16 Mar 2006 17:12:36')

Thanks

------------------------
Hit any User to continue
 
I think one way should be something like this:

[tt]dim d as system.datetime = ctype("2006-03-16T17:12:36.328", system.datetime)
' or perhaps
dim d as system.datetime
system.DateTime.TryParse("2006-03-16T17:12:36.328", d)

' then

messagebox.Show(d.ToString("yyyy-MMM-dd hh:mm:ss"))[/tt]

But perhaps look into usage of the paramters collection?

Roy-Vidar
 
Ta Roy,

Ended up simply using the replace function to remove the T (and reaplce with a " ") and let SQL work it out from there.. works so far as I can see....



------------------------
Hit any User to continue
 
Use the XmlConvert class to convert it from your XmlDocument to a .net DateTime variable, which is then understood natively by SqlParameter objects you would use in your query.

This format is called ISO-8601, and is the W3C-specified format for storing dates in XML. Any other format you see in XML that people send you is merely a string that somewhat resembles a date. ;-)

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
For that sake, once could pass as is (varchar?), since SQL server also recognizes ISO 8601 ;-)

Roy-Vidar
 
Depends on which version of SQLServer you have. The older versions do not recognize it.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top