473,404 Members | 2,137 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,404 software developers and data experts.

ISO 8601 and datetime store/retrieve from DB.

I want to store and retrieve datetime in ISO 8601 format:

'2007-06-02T16:12:08.123-04:34'
or
'2007-06-02T16:12:08.123Z'
When I insert a datetime with SQL Server Management Studio and then I do a
SELECT I loose original "string" and the datetime get converted in a local
datetime.

Suppose I have an handheld in NY and another in Athens, the DB server in
Moscow and the front end application that sees DB data in Rome.
My handheld app stores ISO 8601 datetime into an XML file and send it to the
DB server through a Web Service.

I'd like the user in Rome to see datetimes on a datagrid all with Rome time
zone or with originals timezones or as a string in ISO 8601 format.
How to do that?

I've converted all datetimes to UTC and then stored them without the
trailing Z so that the DB does not convert them.

Can I add a column with the UTC offset to recreate original datetimes or the
overhead before displaying the dataset is too much?
Thanks,
Luigi.
Jun 4 '07 #1
2 3455
Luigi,

I don't think you have to do anything of the sort. If you are already
storing the datetimes in UTC in the database, then I would perform the
conversion to local time based on the current system settings. Once you get
the DateTime from the database, you just have to call ToLocalTime on the
DateTime instance to get the UTC time in local time.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"BLUE" <bluewrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>I want to store and retrieve datetime in ISO 8601 format:

'2007-06-02T16:12:08.123-04:34'
or
'2007-06-02T16:12:08.123Z'
When I insert a datetime with SQL Server Management Studio and then I do a
SELECT I loose original "string" and the datetime get converted in a local
datetime.

Suppose I have an handheld in NY and another in Athens, the DB server in
Moscow and the front end application that sees DB data in Rome.
My handheld app stores ISO 8601 datetime into an XML file and send it to
the DB server through a Web Service.

I'd like the user in Rome to see datetimes on a datagrid all with Rome
time zone or with originals timezones or as a string in ISO 8601 format.
How to do that?

I've converted all datetimes to UTC and then stored them without the
trailing Z so that the DB does not convert them.

Can I add a column with the UTC offset to recreate original datetimes or
the overhead before displaying the dataset is too much?
Thanks,
Luigi.

Jun 4 '07 #2
I've done some tests founding that System.Datetime can handle well datetime
values (no seconds offset allowed and rounding if more than 7 digits
supplied):

2007-06-06T09:03:01.1234567+02:00
SQL Server instead handle only datetime values of this kind:

2007-06-06T09:03:01.123
2007-06-06T09:03:01.123Z

And both are stored as the same value!
How can I store all datetimes with timezone info?
To make comparisons I've decided to store them as UTC, but how to get back
the original values?

To be clear:

My datetime is 2007-06-06T12:03:01.1234567+02:00
I store it as 2007-06-06T10:03:01.123Z
How can I get back 2007-06-06T12:03:01.123+02:00???

I think this is only possible if I add a string column wich holds the
offsett in this format Shh:mm (with S = + or -) right?
Thanks,
Luigi.
Jun 6 '07 #3

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

Similar topics

9
by: Tom | last post by:
Hi There is a datetime type with length 8 in a table I tried to insert the Local System datetime to it from aspx.cs file. But, the outcome are string sysdatetime =...
2
by: Fouad Fahim | last post by:
Hi all, I wonder how we can convert or getting a date in ISO 8601 Format!? Regards, FF
2
by: Kathy Burke | last post by:
Hi, I've read every post I could find but still no luck on why this won't work for me. I have an aspx page (U.S. default, VB, .Net 1.1), where I use the following two variables: Dim varStartTime...
3
by: Roshawn Dawson | last post by:
Hi, I'm reading timestamp values from some log files. I need to merge the date and time values together in ISO-8601 format. I've loaded the date and time values into a dataset successfully. ...
3
by: Tim Cowan | last post by:
Hi, In my application I need to compare whether one time is greater than another. What I am doing right now is taking the current datetime, formatting as string without the time element, and...
0
by: Andy Fish | last post by:
Hello, I'm trying to parse dates in ISO 8601 format. I tried this: DateTime.ParseExact(inputValue, "s", CultureInfo.InvariantCulture) But this only works with one specific format. Is there...
7
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns "1:59:00 PM" it never returns seconds. Database field...
1
by: rowland | last post by:
What's the simplest solution for formatting the output of local time in iso 8601 including the time zone information? Example: "2008-07-25T14:28:43.934-04:00" Thanks, Rowland
3
by: raulbolanos | last post by:
Hello guys, I get this time from DateTime.Now "6/12/2009 11:45:28 AM" and I need to convert it ISO 8601 which is the one that SQL accepts "2009-12-06 11:45:28". What can I do?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.