created_at
created_at
. This is a timestamp that shows when each row was created. This is easy to set as a column in our CREATE TABLE
statements.created_at
value is set automatically.created_at
data, which records the date, time and timezone of a row, we don't have any easy way to render that date data into an edit form (although in real life you would probably never want to edit this information).datetime-local
input type in HTML but that it is not cross-browser compatible.DATE
data type in our tables for user-generated date data.sightings
example above we make the distinction between created_at
, the date the row was created in the database, and date
, the date of the UFO sighting. created_at
is of type TIMESTAMPTZ
because it is auto-generated and does not require a form input.date
input type in a form. In production applications this would also not be ideal, since date
input types are also not well supported (about 90%), but they are much more prevalent than the datetime
input type. See browser compatibility of the date
input type here.DATE
type in the Postgres table we specified above matches the input format we specified in the input form, we can simply pass what's in request.body.date
right into the database.pg
npm library processes the data coming out of the database and transforms it into native JavaScript types. When we get the value of a DATE SQL type out of the database it's a JavaScript Date Object. We can call any of the methods on this value that are specified in the JS Date documentation.moment
library.moment
docs on how to output dates with moment
. Note that moment
will also work with the TIMESTAMPTZ
data type from the created_at
column and any date with timezone data inside it.datetime-local
input type. Chrome supports datetime-local
and the field value can be inserted directly into a Postgres TIMESTAMPTZ
field.date
input type and create a separate input field for time data. Store time data in Postgres using a separate column. Example here. In production applications we would always want to store timezone data, but in Coding Bootcamp Module 3 it's not recommended due to input limitations.