Sean Kimball
Sean Kimball

Reputation: 4494

How to create a date in mysql

I need to create a date in a mysql query - but just the year part, I have tried:

SELECT STR_TO_DATE('01,5,'year(now()),'%d,%m,%Y');

But that does not work.

All I need to do is change the year part - any ideas how to do this?

Upvotes: 0

Views: 312

Answers (2)

ArthurChamz
ArthurChamz

Reputation: 2049

The STR_TO_DATE function does not accept two strings as its first argument, you need to concatenate the day and month with your year expression, using CONCAT.

Try this (SQLFiddle =):

SELECT STR_TO_DATE(CONCAT('01,5,',YEAR(NOW())),'%d,%m,%Y');

Upvotes: 2

John Conde
John Conde

Reputation: 219934

If you know the two other parts just use CONCAT()

SELECT CONCAT(YEAR(CURDATE()), '-05-01')

Fiddle

Upvotes: 0

Related Questions