Datetime C # - Timestamp Postgresql

0

I have a problem inserting the date in PostgreSQL, I have the following:

parametros.Add("descripcion", this.descripcion);
parametros.Add("fecha", this.fecha);
parametros.Add("estado", this.estado);

Program.da.SqlQuery("insert into schtiempos.sorteo (descripcion, fecha, estado) values (@descripcion, @fecha, @estado) returning id;", parametros);

Date in visual is found as datetime(2017/25/03 00:00:00) and in PostgreSQL as Timestamp without time zone, but it does not let me save it in the database for the types DateTime and Timestamp without time zone, what should I do?

    
asked by jok 26.03.2017 в 16:11
source

1 answer

0

You need to force the format of your date to what Postgre needs, now your property this.date is printed like this " 3/27/2017 3:02:09 PM "and you receive the error, you need to force the format in the following way:

parametros.Add("descripcion", this.descripcion);

// Aqui forzamos el formato de la fecha
parametros.Add("fecha", this.fecha.ToString("yyyy/MM/dd hh:mm:ss"));
parametros.Add("estado", this.estado);

Program.da.SqlQuery("insert into schtiempos.sorteo (descripcion, fecha, estado) values (@descripcion, @fecha, @estado) returning id;", parametros);

This will be printed with the desired format 2017/25/03 00:00:00

Note: This only works if this.date is of the DateTime type.

    
answered by 27.03.2017 в 17:05