DateTimeOffset Conversion
See original GitHub issueAccording to the docs, DateTimeOffset is converted to UTC before sending it. So for example,
new DateTimeOffset(2012, 1, 1, 1, 1, 1, TimeSpan.FromHours(-6))
1/1/2012 1:01:01 AM -06:00
Gets converted to:
1/1/2012 7:01:01 AM +00:00
When inserted into the database.
This is great. However, when pulling this value out of the database, the following is returned:
1/1/2012 7:01:01 AM -06:00
It appears that npgsql is using the local timezone when values are pulled out, even though npgsql inserted a UTC offset’ed value.
I would expect either:
1/1/2012 *1*:01:01 AM -06:00
or
1/1/2012 *7*:01:01 AM +00:00
Either is fine since the time is equivalent, but this is definitely not correct:
1/1/2012 *7*:01:01 AM *-06:00*
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Converting between DateTime and DateTimeOffset
Conversions from DateTime to DateTimeOffset · The DateTimeOffset constructor, which creates a new DateTimeOffset object based on a DateTime value ...
Read more >Convert UTC DateTime to DateTimeOffset
I need to convert UTC date strings to DateTimeOffsets . This must work with a timezone which differs from the computers timezone. E.g....
Read more >DateTimeOffset - ConvertTime - C# Extension Methods
DateTimeOffset - ConvertTime. Converts a time to the time in a particular time zone. Try it. public static void Main() { // Define...
Read more >Homw to convert datetimeoffset to datetime in C# ...
Parse(dateString); DateTimeOffset result = TimeZoneInfo.ConvertTime(utc, timezone); // the correct utc offset, in this case +01:00:00 Debug.
Read more >Convert 'datetimeoffset' to 'datetime2' in SQL Server (T- ...
In this case, I use the CAST() function directly within the SELECT statement to explicitly convert between datetimeoffset and datetime2.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@roji I pulled down the driver to figure out what the issue was, and there wasn’t any issues.
A little embarrassing - I tested everything again in linqpad and everything looks good. My only excuse is sleep deprivation. Sorry to waste everyone’s time.
@Silvenga @austindrenski am re-opening so I can take another look, to make sure that we’re doing the right thing. Will try to look at this soon.