DATE AND TIME WITHOUT TIMEZONE

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
JORGEMAL
Posts: 171
Joined: Thu 03 Jul 2008 23:55

DATE AND TIME WITHOUT TIMEZONE

Post by JORGEMAL » Thu 25 Sep 2008 17:20

I am writing a web application with Visual Studio 2005 and PostgreSQL. In my database I have a table with a TIMESTAMP field WITHOUT TIMEZONE which I tried to fill with the Date.Now function of Visual Basic 2005; this function returns the actual date and time with an aggregate of "a.m." or "p.m." at the end. When an INSERT is issued to the database I get the following error message:

***** timezone "a.m." not recognized *****

I checked the type of exception and I get "corelab.postgresql.pgsqlexception".

Am I doing something wrong?

My version of PostgreSQLDirect.NET is 3.75.31.0

P.D.
If I change the time format in Regional Settings to be displayed in a 0-24 option then everything works as expected.

With respect,
Jorge Maldonado

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 26 Sep 2008 08:33

Please send us (alexsh at devart.com) your code where you create the object of the CoreLab.PostgreSQL.PgSqlCommand class and call its method. We need to know the way you transfer the result of the Date.Now function to your PostgreSQL database.

JORGEMAL
Posts: 171
Joined: Thu 03 Jul 2008 23:55

Post by JORGEMAL » Fri 26 Sep 2008 14:04

Shalex wrote:Please send us (alexsh at devart.com) your code where you create the object of the CoreLab.PostgreSQL.PgSqlCommand class and call its method. We need to know the way you transfer the result of the Date.Now function to your PostgreSQL database.
Here is the code. It is part of a class; it's a method that inserts a record to a PostgreSQL log table which receives several parameters being Fecha of type Timestamp in the database.

Public Shared Sub NuevoEvento(ByVal UserId As String, ByVal Fecha As DateTime, _
ByVal Ubicacion As String, ByVal Detalle As String, _
ByVal Mensaje As String, ByVal Tipo As String, ByVal Stack As String)
Try
Dim strConn As String = ConfigurationManager.ConnectionStrings("PgSqlConnection").ConnectionString
Dim pgConn As New PgSqlConnection(strConn)
Dim strQuery As String
strQuery = "INSERT INTO Eventos (Fecha, UserId, Ubicacion, Detalle, Mensaje, Tipo, Stack) "
strQuery = strQuery + "VALUES ('" + Date.Now + "', '" + UserId + "', '" + Ubicacion + "', '"
strQuery = strQuery + Detalle + "', '" + Mensaje + "', '" + Tipo + "', '" + Stack + "')"
Dim pgCmd As New PgSqlCommand(strQuery, pgConn)
pgConn.Open()
If pgCmd.ExecuteNonQuery() = 0 Then
Utilerias.DespliegaMensaje("Ha ocurrido un error al insertar el registro en archivo de EVENTOS.")
'Else
'Utilerias.DespliegaMensaje("Se ha insertado el registro de eventos satisfactoriamente.")
End If
pgConn.Close()
Catch ex As Exception
Utilerias.DespliegaMensaje(ex.Message + "\n \n" + ex.GetType().ToString + "\n \n")
End Try

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 29 Sep 2008 13:22

Please try changing the format of the Date.Now property in your code to the following: Date.Now.ToString("yyyy/M/d H:mm:ss"). It should resolve this problem. You can also use the CoreLab.PostgreSql.PgSqlCommand object with parameters. If there will be any difficulties, please let us know.

Post Reply