Kumari Manisha
Kumari Manisha

Reputation: 682

add datetime field value to integer field value in mysql

Is it possible to add one datetime field value like 2013-06-22 09:46:00 to one or more integer field value like1(represents days column)2(represents hours column) then the result obtain after adding datetime value to integer must be in datetime form, so that i can compare with another datetime field value. Like if i get the result after adding with the integer field 2013-06-23 11:46:00, i wants to compare it with another datetime field value, so that if the result value is greater than the compared value then only it w'll give me result.

I know how it w'll work in php but i wants to do through query.

Any help will be appreciated.

Upvotes: 2

Views: 1214

Answers (1)

Abhay
Abhay

Reputation: 6645

I think what you need is the MySQL's date_add() function - http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add.

For example, DATE_ADD('2013-06-22 09:46:00', INTERVAL 1 DAY), where you may replace the date-time and day interval with the corresponding column names.

UPDATE Let us assume, the date-time field is called FIELDA and the integer field is called FIELDB representing days, then the function might be called as:

DATE_ADD(FIELDA, INTERVAL FIELDB DAY);

If however the integer field represent hours, you may call it as:

DATE_ADD(FIELDA, INTERVAL FIELDB HOUR);

Hope above helps!

Upvotes: 1

Related Questions