Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

timestamp with timezone postgresql mapping

Tags:

c#

postgresql

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;
like image 642
shubhangi Motling Avatar asked Apr 05 '13 10:04

shubhangi Motling


People also ask

How does Postgres store timestamp with timezone?

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.

How do you timestamp with a time zone?

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.

Does timestamp include timezone?

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.

What is timestamp without 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).


1 Answers

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.

like image 159
Manus Creationis Avatar answered Oct 20 '22 22:10

Manus Creationis