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
5
votes
1 answer

Why don't DateTime.ToString("R") and DateTime.TryParseExact round trip?

I'm implementing conditional requests in a Web service. The backend can easily retrieve the last modified date of an entity, so I'm sending Last-Modified and getting back If-Modified-Since. The RFC for HTTP Dates specifies a format that is the…
Steve Howard
  • 6,737
  • 1
  • 26
  • 37
5
votes
4 answers

How to tell if it's British Summer Time

I have the following code, which should return an offset of 60 (to show that in the UK at present, we are in British Summer Time - ie. 60 minutes ahead of GMT): var info = TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard…
Mark
  • 7,778
  • 24
  • 89
  • 147
5
votes
3 answers

Storing a c# DateTimeOffset value in a SQL Server 2005 database

I want to store a a c# DateTimeOffset value in a SQL Server 2005 database. Sql 2008 has this as a built-in-type, but SQL Server 2005 does not. The DateTimeOffset structure has a DateTime value which I store as DateTime, an an Offset property (of…
Anthony
  • 5,176
  • 6
  • 65
  • 87
5
votes
2 answers

DateTimeOffset in Log4Net

What is log4net.Layout.PatternLayout value to output DateTimeOffset data type to database? This is what I have currently in configuration file for log4net: ....
4
votes
2 answers

Showing culture aware short date and time string from DatetimeOffset in XAML

I've a WPF4 Application. There I bind an UI Control to a DateTimeOffSet value. For example a textblock But I want a culture aware display of the value. So for example…
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
4
votes
1 answer

Converting a datetime to a particular timezone but in a specific format c#

I am not entirely sure if this is even possible and I have tried a number of things, short of writing an algorithm. I have a variable of type datetime which I want to convert into a specific timezone and into a specific format. Let me give an…
samar
  • 5,021
  • 9
  • 47
  • 71
4
votes
1 answer

Is this request generated by EF Core buggy or is it my code?

Introduction I'm using EF Core with .NET 5.0 and SQL Server Express. Basically I'm wondering if it generated a buggy SQL query or if my code is buggy (probably :D). I provided a mre at the bottom of the question, but hopefully the problem becomes…
Lukas-T
  • 11,133
  • 3
  • 20
  • 30
4
votes
1 answer

DateTimeOffset display after daylight savings change

I have a question about DateTimeOffset and daylight savings time. To explain my question lets assume that right now the date and time is: 11/6/2010 10:15:00 AM If I run this code: DateTimeOffset myTime =…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
4
votes
1 answer

datetimeoffset vs datetime2 for UTC on SQL Server

Are there any benefits to storing a UTC timestamp in a datetimeoffset field vs datetime2? It seems they're essentially the same. +------------------------------------+-----------------------------+ | datetimeoffset | datetime2 …
Damon Malkiewicz
  • 393
  • 5
  • 15
4
votes
0 answers

How to vectorize a pandas DateOffset?

I need to offset a DateTimeIndex index by a CustomBusinessDay, a trading day offset, which I instantiate like so: import pandas_market_calendars as mcal TCal = mcal.get_calendar('NYSE') from pandas.tseries.offsets import CustomBusinessDay TDay =…
4
votes
3 answers

Problem to import datetimeoffset from csv file to a table via SSIS

I've a csv as a source file that I'm trying to load the data from this file to a stage SQL server table. There are three date columns. The below is an example of values of these columns: 2007-10-02T08:46:13+02:00 On SQL server side, I've defined…
Florentina
  • 85
  • 1
  • 1
  • 10
4
votes
2 answers

Changing current user timezone based on server UTC offset and user UTC offset

im writing a twitter web service in php. When a user signs in, i receive this node: -18000 I have to change the script's timezone so that it adapts to the user's real timezone. The only php function i have found for this…
Andres SK
  • 10,779
  • 25
  • 90
  • 152
4
votes
2 answers

Java LocalDateTime/ OffsetDateTime to Swift 4

What's the equivalent of LocalDateTime and OffsetDateTime in Swift 4? I am trying to encode Java dates and decode them in Swift using Json. It seems like there is only one Date object in Swift.
gke
  • 43
  • 4
4
votes
1 answer

entity framework, migrate from datetime to datetimeoffset

what we want: We have a column in a table in a sql server database, whose data type is datetime. We decided to change data type of this column into datetimeoffset(7). what we have got so far: -first approach: The way mostly suggested to do this (as…
Shahryar Saljoughi
  • 2,599
  • 22
  • 41
4
votes
2 answers

DateTimeFormatter.ISO_OFFSET_DATE_TIME not working as expected

Based on this Java Date Time - OffsetDateTime.format() Examples article and this official documentation for DateTimeFormatter I would expect my OffsetDateTime to be serialized as 2011-12-03T10:15:30+00:00 where the offset the offset is +00:00 since…
eztinkerdreams
  • 381
  • 2
  • 3
  • 17