How Can I map "timestamp with time zone" datatype from postgreSql to System.Data.DbType
I need to pass parameter as it will go to the column which has "timestamp with time zone"
following is my code:
var pOrderDate = cmdOrder.CreateParameter();
pOrderDate.ParameterName = "OrderDate";
pOrderDate.DbType = System.Data.DbType.DateTime;
pOrderDate.Value = objOrder.OrderDate;
cmdOrder.Parameters.Add(pOrderDate);
Following line causes problem:
pOrderDate.DbType = System.Data.DbType.DateTime;
The timestamptz datatype is a time zone-aware date and time data type. PostgreSQL stores the timestamptz in UTC value. When you insert a value into a timestamptz column, PostgreSQL converts the timestamptz value into a UTC value and stores the UTC value in the table.
For timestamp with time zone , the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT ). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone.
The date timestamp also doesn't include timezone information, yet a lot of people use it. Of course, that of itself is not an answer. It's valid to use timestamp and date for any timestamps and dates which are always in the same timezone, or are being stored relative to some known timezone.
The TIMESTAMP (also known as TIMESTAMP WITHOUT TIME ZONE ) and TIMESTAMPTZ (also known as TIMESTAMP WITH TIME ZONE ) types stored as a 64-bit integer as a microsecond offset since 1970-01-01 in CRDB and as a 64-bit integer microsecond offset since 2000-01-01 in PostgreSQL (by default).
Have you considered trying the DateTimeOffset class in .NET?
I'm unaware of how it maps to Postgres "DateTime with Timezone" type, but it has a 1:1 correlation with what I believe would be the MSSQL equivalent (also called DateTimeOffset).
Note that the naming here is quite poor - the type represents a DateTime + Offset, and not just the Offset itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With