I have a database with 10+ columns. Three of the columns represent the day, the month and the year. I now need a date as one Datatype.
I already tried some diffrent solutions explained on the internet, but they didn't work for mysql. And I can't find the mistake I made.
SELECT *,
CAST(
CAST(CREATE_YEAR AS VARCHAR(4)) +
RIGHT('0' + CAST(CREATE_MONTH AS VARCHAR(2)), 2) +
RIGHT('0' + CAST(CREATE_DAY AS VARCHAR(2)), 2)
AS DATETIME)
from incident_view
The name of the three columns are : CREATE_DAY, CREATE_MONTH and CREATE_YEAR.
Example how I want it to work out: The Column DAY has the number 27 in it, the month the number 5 and the year the number 2015. I want to the be displayed like : 27.5.2015 .
SELECT *,
STR_TO_DATE(
CONCAT( CREATE_DAY, '/', CREATE_MONTH, '/', CREATE_YEAR ),
'%d/%m/%Y'
) as rcvd_date
FROM incident_view
where CUSTOMER_COMPANY_NAME = "Company" AND (create_month = MONTH(NOW() - INTERVAL 1 MONTH) AND (create_year = YEAR(NOW() - INTERVAL 1 MONTH)))
This sql achieved me to have a logical Column in my database which is called rcvd_data. But it shows me the day-month-year-hour-minute-seconds, but I only need the day-month and the year.
Example of the data field : 01/02/2016 00:00:00
I would appreciate any help. Thank you.