Include date/time field in postgres (Zend)

Asked

Viewed 440 times

3

I have the following code:

View:

{
    xtype: 'timefield',
    name: 'attendance_time',
    fieldLabel: 'Hora',
    inputWidth: 100,
    format: 'H:i',
    submitFormat: 'H:i',
    altFormats: 'H:i',
}

Model:

{
    name: 'attendance_time',
    type: 'date',
    dateFormat: 'H:i'
}

Field on the bench:

ALTER TABLE person_attendances ADD COLUMN attendance_time TIME(0) DEFAULT CURRENT_TIME;

Error while trying to include:

SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type time: "2019-10-03T01:15:00", query was: INSERT INTO "person_attendances" ("person_id", "origin", "name", "Category", "Description", "tag", "attendance_date", "attendance_time", "title", "id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

1 answer

1


According to that answer in the SOEN, you should keep field as string, and when loading the value, convert it to timestamp. That’s because the guy timestamp takes the standard seat format, not as specified in php

using ::TIMESTAMP will use DB default time format, the format Depend on your DB Culture

Indication is that the field is a string (attendance_time text) and when loading convert , for example with the function to_timestamp:

SELECT TO_TIMESTAMP(attendance_time, 'H:i')
FROM person_attendances

As discussed in comment, if the idea is to take the current time, you can keep the idea of the field type string and in itself php you get this information:

$attendance_time = date('H:i');

The "problem" in this case is that the information will be taken from the client side; if it is in a different zone from the server (and/or other clients), there may be information conflict. That being a downside, you can take the bank itself:

select FORMAT(GETDATE() , 'HH:mm')
  • I understood, however I wanted to format it only to save H:i, because the field in DB is time. I wonder if?

  • @Luisfelipe, you just need to H:i (guy 23:59)? if yes, why use timestamp? you can use string direct and wouldn’t even need to convert.. no?

  • Ah my idea of using the team is because I wanted to get the current_time whenever I add a new record, for example.

  • I will put in the answer an alternative to take in php these info (better than in comment =p)..

  • I added the "s" of seconds in the model and there was "dateFormat: 'H:i:s' " and it worked, no more error appears when inserting. Exactly because I didn’t understand kk

  • good, solving is what matters :P I will try to search here and if I find something I pass

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.