Sunday, March 11, 2012

datetime format problem

Is there any standard function for inserting datetime values to an sql table. I'm having a problem because some operating systems are in english and some operating systemes are in spanish.. When I insert a value '2005-02-15 12:00:00' it works on the english operating system, but it doesn't in the spanish one... any ideas?try GETDATE ( )|||I am getting the date/time from a date time picker in visual basic.. it's not the current date.|||Define date time picker. Sounds like you need one or more of the following:

A smarter date time picker that converts all datetimes to a standard format.
To write a routine that adds intelligence to your picker.
Some VB function that does b. for you. The lack of strong-typing in VB may make this very difficult.

SQL Server has this interesting trait of trying to do exactly what you ask it to do. You may also want to read up on Cast/Convert in SQL BOL.|||???

If it is a VB control I would think it would be returning a VB datetime value, which is just a number with no formatting applied.

But if you are converting this to a string and submitting it to SQL Server as a datetime value (which you shouldn't be doing), then this format should be universally recognized by SQL Server:

yyyy-mm-dd hh:mi:ss

...where hh uses a 24 hour clock.|||If it is a VB control I would think it would be returning a VB datetime value, which is just a number with no formatting applied.Excellent point. So, diegocro, why is the value being sent a text string?|||Am I missing something (very possible)? How else can you send a date value from VB to SQL?|||Unlikely. You don't miss much.

But the VB code could be converting or storing the data in any number of odd ways before it is submitted to SQL Server. A lot can happen to data at point B while it is traveling from point A to point C...|||Or you could try CAST or CONVERT to change the text string to a DATE format.

e.g. CONVERT(datetime,'2005-02-15 12:00:00' ,120) (see BOL for more detail)|||you can do something like this

convert(datetime,datepickervalue,101)|||[sniped]
[sniped]
[sniped]
[sniped]
[sniped]|||ok
CONVERT(datetime,'2005-02-15 12:00:00' ,120) works, thanks a lot.

No comments:

Post a Comment