Saving date with Datetime picker doesn't keep the same format

Hello forest,

Feature(s) impacted

Widget Date

Observed behavior

We use an IsoDate (YYYY-MM-DD) type to store a date (restitutionMeetingDate) in the database, so the SQL type is a string.

Here is the definition in the model :
Capture d’écran 2021-11-29 à 13.59.17

We choose to use a Datetime picker to display it on the UI on forest

When we update the record, the date format stored is not the good one. Here is what we have in the database after saving :

We would like to have this format instead : 2021-11-30

Thanks for helping us

Hello @gaelperon ,

Can you please provide us the agent type and the version you are using?

Hello Mian,

"dependencies": {
    "axios": "^0.21.0",
    "body-parser": "^1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17",
    "express-jwt": "5.3.1",
    "forest-express-sequelize": "^8.0.7",
    "morgan": "1.9.1",
    "pg": "8.5.1",
    "require-all": "^3.0.0",
    "sequelize": "^5.15.0"
  },

Hey @gaelperon,

Thanks for your answer.

Can I ask you first if there is any particular reason why you are using a string type in your database (and in your model definition) and not a date/timestamp type?

Thanks.

Hello Mian,

"dependencies": {
    "axios": "^0.21.0",
    "body-parser": "^1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17",
    "express-jwt": "5.3.1",
    "forest-express-sequelize": "^8.0.7",
    "morgan": "1.9.1",
    "pg": "8.5.1",
    "require-all": "^3.0.0",
    "sequelize": "^5.15.0"
  },

Hi @adriguy

To avoid dealing with timezones we prefer to store the date as a string instead of full date :slight_smile:

@gaelperon,

Are you using a PostgreSQL database?
There exists a date type that does not include any time or timezone.
Using this, I guess everything should work properly out of the box.

If you really want to keep your dates saved as string, I guess you have 2 solutions:

  • Either you don’t use the edit widget date picker
  • Or you override every PUT route of your project where there are some dates formatted as string, and you transform the received timestamp value into the format you want.

Let me know!
Thanks.

Thank you for your answer.

We’ll try to convert our strings to Date format (we use postgres with typeORM).

1 Like