Answer a question

I am new with nestjs. How can I set columns that accepts Date format and dateTime format?

Not in both cases, the columns are two differents column, one accept Date and other dateTime.

Answers

You can see the docs here that explains the @Column decorator. In @Column there is an option called type -> here is where you specify which type of date you want to store for that specific column.

More on column types here.

For example (using PostgreSQL):

@Column({ type: 'date' })
date_only: string;

@Column({ type: 'timestamptz' }) // Recommended
date_time_with_timezone: Date;

@Column({ type: 'timestamp' }) // Not recommended
date_time_without_timezone: Date;

Note that date_only is of type string. See this issue for more information.

Hope it helps :)

Logo

华为、百度、京东云现已入驻,来创建你的专属开发者社区吧!

更多推荐