Questions tagged [datetimeoffset]

DateTimeOffset is a data structure that encapsulates a DateTime value and the Offset from UTC that the value reflects. It is used to represent an instantaneous moment in time, while still capturing the perspective of the observer.

DateTimeOffset is a data structure that encapsulates a DateTime value and the Offset from UTC that the value reflects. It is used to represent an instantaneous moment in time, while still capturing the perspective of the observer.

Contrary to popular belief (and to much of the documentation) the offset provided does not represent a time zone. One might start with a time zone to obtain the offset, but it is a one-way function. You can not determine the time zone by the offset alone. For a better understanding of this, see this community wiki answer.

The preferred serialization format for this type of data is defined as part of the ISO-8601 specification.

  • Example: 1997-07-16T19:20:30+01:00

DateTimeOffset and similar structures are presented in:

Please update this list if you are aware of similar structures in other languages, frameworks, or databases

614 questions
4
votes
2 answers

Convert string to DateTimeOffset ignoring time zones

I've created a string extension method which will convert the specific string to DateTimeOffset. I executed the following method: public static DateTimeOffset? ConvertToDateTimeOffset(this string text) { DateTimeOffset date; if…
pbarna
  • 51
  • 1
  • 4
4
votes
2 answers

datetimeoffset hibernate mapping

I'm trying to use hibernate with ms sql server and have difficulties mapping the sql type datetimeoffset to java. If I try to set the mapping type in the reverse engineering configuration with: I get an error saying sth. like …
uzay
  • 51
  • 1
  • 3
4
votes
1 answer

Create a DateTimeOffset set to Midnight in a different TimeZone from server

I have a server set to EST and am wondering what I need to do to create a DateTimeOffset set to Midnight of the current day but in a different timezone? For example PST?
Chris
  • 1,006
  • 10
  • 13
4
votes
2 answers

Converting string to datetimeoffset in SQL Server and Postgresql

In SQL server I have a column that stores dates of this format: 2017-06-22T00:43:15+0300 as strings. What I'm trying to do is cast these strings into actual datatimeoffset data in order to handle them as dates. So far I have found multiple…
Mewtwo
  • 1,231
  • 2
  • 18
  • 38
4
votes
1 answer

DateAdd with a DateTimeoffset sometimes removes the offset

In an attempt to remove the time from a DateTimeOffsetValue, I can across a situation where the time zone was being removed - I'm guessing there is an implicit conversion to a DateTime happening here, but why? DECLARE @d DATETIMEOFFSET =…
Jeremy
  • 44,950
  • 68
  • 206
  • 332
4
votes
3 answers

Example of ambiguous DateTimeOffset

We have DateTimeOffsets in Database/Model. To display these values in Web, we convert the DateTimeOffsets into the current user's timezone. According MSDN, DateTimeOffset can be ambiguous in a specific TimeZone: TimeZoneInfo.IsAmbiguousTime Method…
Thomas Zweifel
  • 627
  • 1
  • 6
  • 19
4
votes
2 answers

How to get all IANA Timezones from an offset in NodaTime?

In our ASP.NET MVC 5 application we have user profiles with a Timezone ID (IANA). public class User { public int Id { get; set; } public string TimeZoneId { get; set; } } The task is to send all users an email at 6 AM local time. Our plan…
Fred Fickleberry III
  • 2,439
  • 4
  • 34
  • 50
4
votes
1 answer

How to build custom pandas.tseries.offsets class?

I want to find a way to build a custom pandas.tseries.offsets class at 1 second frequency for trading hours. The main requirement here is that the time offset object would be smart enough to know the next second of '2015-06-18 16:00:00' would be…
Jianxun Li
  • 24,004
  • 10
  • 58
  • 76
4
votes
1 answer

DateTimeOffset default value

I would like to set default value to DateTimeOffset - it should not be DateTime.Now but rather DateTime.MinValue or default(DateTime) Any thoughts how can I do it? This code: DateTimeOffset d = new DateTimeOffset(DateTime.MinValue) throws an…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
4
votes
1 answer

Why doesn't Azure Table Storage support DateTimeOffset?

Before anyone closes this as a duplicate, I am aware that Azure Table Storage doesn't support the DateTimeOffset type natively (MSDN states as much; trying to read and write entities having DateTimeOffset properties doesn't throw an exception, but…
Steven Rands
  • 5,160
  • 3
  • 27
  • 56
4
votes
3 answers

Entity Framework 4 maps DateTimeOffset to SQL datetime in Visual Studio 2010

I'm using Visual Studio 2010 RTM with .NET/Entity Framework 4 RTM with a model driven design approach. When I create an entity with a DateTimeOffset field the EF modeler tries to map the DateTimeOffset to a SQL datetime instead of a SQL…
Carvellis
  • 3,992
  • 2
  • 34
  • 66
4
votes
1 answer

DateTimeOffset TotalHours returns different values

The following code returns 9.25 when I feel it should return 8.25, what have I misunderstood? (new DateTimeOffset(2014,09,04,08,15,00,new TimeSpan(0,0,0))).Subtract(new DateTimeOffset(2014,09,04,08,15,00,new TimeSpan(0,0,0)).Date).TotalHours more…
Old fart
  • 590
  • 1
  • 4
  • 12
4
votes
1 answer

Forcing ISO 8601 with CSVHelper

I'm trying to get a ISO8601 formatted date in the following format yyyy-MM-ddTHH:mm:ss.fffffff zzz to a .csv using CsvHelper. public System.DateTimeOffset ChangeDT { get; set; } Map(m => m.ChangeDT).ConvertUsing(row =>…
Joe R.
  • 123
  • 11
4
votes
1 answer

How to keep the timezone when parsing a date?

I parse a date that comes with time zone information, say: 1/7/2008 11:00:00 AM -0700. The -0700 corresponds to the current time offset here in California, since we are now in PDT. If I parse it and show it…
avernet
  • 30,895
  • 44
  • 126
  • 163
4
votes
5 answers

Specified Cast is not valid when DataBind to Nullable DateTimeOffset and field is NULL

I've created a simple CompositeControl and exposed a Nullable DateTimeOffset property. I'm binding the control to a SQL Server DateTimeOffset field using DateTimeOffset='<%# Bind("myDateTimeOffsetField") %>' This works great when the DateTimeOffset…
PapillonUK
  • 642
  • 8
  • 20