Kalas Yagami
Kalas Yagami

Reputation: 183

JHipster actual date

Is there a way to get a field that return actual date/hour when I create an entity ? Cause post-editing my entities always gives me errors.

I've searched about it, and didn't seen anything. I tried with DateTime etc, but I would like that my field auto-fill with the date when the entry in the DB is made.e

Upvotes: 2

Views: 2041

Answers (2)

Gaël Marziou
Gaël Marziou

Reputation: 16294

You can do it in code as Rousseau Alban explained or if you only want current date, you can let the database do it for you on insert: just add a default value to your column in the Liquibase changelog created by JHipster for your table's entity, it should be anmed something like 2016***_added_entity_***.xml. You can see an example in src/main/resources/config/liquibase/changelog/00000000000000_initial_schema.xml in jhi_user table for field created_date.

    <column name="created_date" type="timestamp" defaultValueDate="${now}">
        <constraints nullable="false"/>
    </column>

Drop your database and restart your app to re-create it.

Upvotes: 0

Rousseau Alban
Rousseau Alban

Reputation: 104

When saving your entity newly created, you can add a LocalDate.now() or LocalDateTime.now() to the field you want. Then you should hide the field Date in your form. It worked for me. If you still want your field to show a date/time picker, it is already done : the date/time picker should select the actual date.

hope this helps

Upvotes: 3

Related Questions