sivakumar tadisetti sivakumar tadisetti - 3 months ago 7x
SQL Question

How to add datetime and time

In my database table, I am storing current date and time using NOW() function and I mentioned column datatype as DATETIME, which is the column I am using to store date and time and it is storing in the format of YYYY-MM-DD HH:MM:SS

I am trying to write a query that selects the date and time from my database table column and adding HH:MM to retrieved date and time like

SELECT date FROM tablename by adding fetched date which is (**YYYY-MM-DD HH:MM:SS**) + **HH:MM**

The above query is just to make you know what I was trying :-)

Actually I don't know how to add datetime and time in mysql while retrieving the data.

How can we add YYYY-MM-DD HH:MM:SS and HH:MM while retrieving the data in mysql

Thank you for help in advance :-)


You can use ADDTIME in MySQL:

SELECT ADDTIME('2016-07-15 18:00:00', '02:30');

or with DATEADD

SELECT DATE_ADD('2016-07-15 18:00:00', INTERVAL '02:30' HOUR_MINUTE);

Both Result as:

2016-07-15 20:30:00