We are implementing PostgreSQL and have also decided to use NodaTime instead of standard .NET DateTime. PostgreSQL has a "timestamp with time zone" type, and NodaTime returns a Date and time value with a time zone via the SystemClock.Instance.Now method. However, the value returned by SystemClock.Instance.Now (2015-07-17T13:22:52Z) is not directly writable to the PostgreSQL field. Is there a best practice for dealing with NodaTime/PostgreSQL implementations?
From what I understand, "timestamp with time zone" is a misnomer anyway - it's just "you supply a time zone with a local value, PostgreSQL will store UTC"... in other words, it's really an extra conversion rather than storing more data.
If you're just trying to store an Instant
, then timestamp
should be fine as a data type. In terms of getting the value to the database, you should probably just convert it to a DateTimeOffset
, and let the driver handle that. You'll want to use Instant.ToDateTimeOffset
when storing, and Instant.FromDateTimeOffset
when retrieving.
See more on this question at Stackoverflow