ERROR: the time zone p.m. is not recognized, Postgres

0

I have a table similar to this one:

------------------------------
| id |       fecha           |
------------------------------
| 1  |  2018-06-18 14:30:00  |
| 2  |  2018-06-18 14:31:40  |
------------------------------

The important thing is in the date, since I need it to make another query.

In Start I get the last record of the table with the Ultimate function :

    public static DataTable Ultimo()
    {
        DataTable DtResultado = new DataTable("ultimo");
        NpgsqlConnection SqlCon = new NpgsqlConnection(Conexion.Cn);
        NpgsqlCommand SqlDat = new NpgsqlCommand(String.Format("select * from " + table + " order by fecha desc limit 1"), SqlCon);
        SqlCon.Open();
        NpgsqlDataReader dr = SqlDat.ExecuteReader(CommandBehavior.CloseConnection);
        DtResultado.Load(dr);
        dr.Close();
        SqlDat.Dispose();
        SqlCon.Close();
        return DtResultado;
    }

So almost everything ok , since the date returns me well on my pc: 2018-06-18 14:31:40 , but in another I return: 2018-06-18 2:31:40 p.m. .

The fact is that I need all the data of that date so that said fecha sent it to the PorFechaExacta function as I get in the previous query:

    public static DataTable PorFechaExacta(string date)
    {
        DataTable DtResultado = new DataTable("fechaExacta");
        NpgsqlConnection SqlCon = new NpgsqlConnection(Conexion.Cn);
        Console.Write(date);
        NpgsqlCommand SqlDat = new NpgsqlCommand(String.Format("select * from " + table + " where date(fecha)='"+date+"'"), SqlCon);
        SqlCon.Open();
        NpgsqlDataReader dr = SqlDat.ExecuteReader(CommandBehavior.CloseConnection);
        DtResultado.Load(dr);
        dr.Close();
        SqlDat.Dispose();
        SqlCon.Close();
        return DtResultado;
    }

And there's a very long error with title:

  

ERROR: the time zone

asked by Shassain 20.06.2018 в 01:49
source

1 answer

0

You must give the correct format to the date, it would be something like this:

public static DataTable PorFechaExacta(string date)
{
     IFormatProvider culture = new CultureInfo("en-US", true);
     DateTime NewDate = DateTime.ParseExact(date, "yyyy-MM-dd hh:mm:ss", culture);
     date = NewDate.ToString("yyyy-MM-dd HH:mm:ss");

     DataTable DtResultado = new DataTable("fechaExacta");
     NpgsqlConnection SqlCon = new NpgsqlConnection(Conexion.Cn);
     Console.Write(date);
     NpgsqlCommand SqlDat = new NpgsqlCommand(String.Format("select * from " + table + " where date(fecha)='"+date+"'"), SqlCon);
     SqlCon.Open();
     NpgsqlDataReader dr = SqlDat.ExecuteReader(CommandBehavior.CloseConnection);
     DtResultado.Load(dr);
     dr.Close();
     SqlDat.Dispose();
     SqlCon.Close();
     return DtResultado;
 }

Greetings

    
answered by 02.07.2018 в 15:43