MYSQL: how to set date (makedate?) With month, day and year

I have three columns, y, m and d (year, month and day) and want to save this as a date.

What function would I use on mySQL for this?

Apparently makedate uses the year and day of the year (see below), but I have a month.

I know that I can use STR_TO_DATE (str, format), building a string from (y, m, d), but I would suggest that there is an easier way to do this.

LIST OF REFERENCES

MAKEDATE (year, day)

Returns the date, year, and year. dayofyear must be greater than 0 or the result is NULL.

+7
date mysql
source share
3 answers

I believe that you can use the string in the appropriate format:

UPDATE table SET my_date = '2009-12-31'; 

Edit: Yes, you can just check it in MySQL 5.1.

+8
source share

This is not very readable, but the following:

 SELECT'1900-01-01' + INTERVAL y-1900 YEAR + INTERVAL m-1 MONTH + INTERVAL d-1 DAY FROM ... 

Not sure if this is more efficient than using CONCAT and STR_TO_DATE.

+5
source share

Hope this works.

 str_to_date( concat( year( curdate( ) ) , '-', month( a.dob ) , '-', day( a.dob ) ) , '%Y-%m-%d' ) 

Where a.dob is my column name that has DATE

+1
source share

All Articles