user10332687
user10332687

Reputation:

Format a date in mysql

To get a date I can do:

select date(now())

And it will give me:

2018-11-30

How would I format it as:

YYYYMMDD

So it gives me:

20181130

Is there a better way than:

select replace(date(now()), '-','')

Upvotes: 0

Views: 33

Answers (1)

fifonik
fifonik

Reputation: 1606

SELECT DATE_FORMAT(NOW(), '%Y%m%d')

Manual: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

Upvotes: 1

Related Questions