sivakumar tadisetti sivakumar tadisetti - 1 year ago 79
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 :-)

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download