473,387 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ISO dates?

To support an application, I am integrating it with with Sqlserver
2000. The task is simple: get the data at regular intervals, and
write it into a table dedicated for that application. One of the
fields I receive is a date, and it is formatted as an ISO date. A
sample value looks like this: "2004-07-09-15.37.52.077258".

SQLServer doesn't support this date format, though. The closest I
have found is the style code "21" or "121" which accepts input as
"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
and convert() calls but no solution yet.

Is there a way to transform the data to conform to this style accepted
by Sqlserver? I would like to do this in the INSERT statement itself
and not have to code application logic (i.e., user-defined function,
etc.) for it.
Jul 20 '05 #1
2 1555
No, not without using complex CAST functions, UDFs, or INSTEAD OF
triggers.

I suggest you stick to the simplified ISO 8601 syntax, for example
"20040709 15:37:52.077". If you must, you can use
"2004-07-09T15:37:52.077", which will also alway work correctly on
version 2000 of SQL-Server.

Also note that SQL-Server will not accept more than 3 digits for
milliseconds.

HTH,
Gert-Jan
php newbie wrote:

To support an application, I am integrating it with with Sqlserver
2000. The task is simple: get the data at regular intervals, and
write it into a table dedicated for that application. One of the
fields I receive is a date, and it is formatted as an ISO date. A
sample value looks like this: "2004-07-09-15.37.52.077258".

SQLServer doesn't support this date format, though. The closest I
have found is the style code "21" or "121" which accepts input as
"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
and convert() calls but no solution yet.

Is there a way to transform the data to conform to this style accepted
by Sqlserver? I would like to do this in the INSERT statement itself
and not have to code application logic (i.e., user-defined function,
etc.) for it.


--
(Please reply only to the newsgroup)
Jul 20 '05 #2
You can't store time with higher resolution than 1/300th second (in
multiples of .010 + .000, .003 or .007) in a DATETIME column. Also, I think
it's generally better to do this in application logic, unless you have many
places where the time values are inserted. For example, Perl can do a lot
more with regular expressions than you can easily implement in T-SQL.

But this should work if the format never varies (eg. if your months and day
values are always 2 digits each, and the year always 4 digits)

declare @dt varchar(26)
set @dt = '2004-07-09-15.37.52.077258'
print left(@dt,10)+' '+replace(substring(@dt,12,12),'.',':')
select cast(left(@dt,10)+' '+replace(substring(@dt,12,12),'.',':') as
datetime)

"php newbie" <ne**********@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
To support an application, I am integrating it with with Sqlserver
2000. The task is simple: get the data at regular intervals, and
write it into a table dedicated for that application. One of the
fields I receive is a date, and it is formatted as an ISO date. A
sample value looks like this: "2004-07-09-15.37.52.077258".

SQLServer doesn't support this date format, though. The closest I
have found is the style code "21" or "121" which accepts input as
"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
and convert() calls but no solution yet.

Is there a way to transform the data to conform to this style accepted
by Sqlserver? I would like to do this in the INSERT statement itself
and not have to code application logic (i.e., user-defined function,
etc.) for it.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Riley | last post by:
The date fields being saved by a VB program were being saved as #2003-11-22#. For reasons unknown to me these dates began to be saved as "11/22/2003" All of these dates were made dates with the...
7
by: Alistair | last post by:
diary_date = request.form("diary_date") - (from a populated drop down list) strSQL = "SELECT saz_title, saz_text from saz_details where saz_date =#" & diary_date & "#" a response.write...
5
by: PW | last post by:
<rant> Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the butt! I seem to get caught out so many times. I realise its my own fault, but going from the posts in this...
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
2
by: Rachel Suddeth | last post by:
Is there a way to have the non-selectable dates (those before MinDate and after MaxDate) draw differently so my users can see right away what dates aren't allowed? I'm not seeing it... ...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
1
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie...
7
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database....
2
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.