Thursday 15 May 2014

php - add datetime field value to integer field value in mysql -


Is it possible to add a datetime field value such as 2013-06-22 09:46:00 One or more integer field values ​​such as 1 (indicates day column) 2 (indicates hour column) then after adding the datetime value to the result integer Receives should be in datetime form so that I can compare it with any other Datat field value. Like if I get the result after adding the integer field 2013-06-23 11:46:00 , then I want to compare it to another datat field value, so that the value of the result is bigger The comparative price will only result in me.

I know how it will work in PHP but I want to do it through query.

Any help would be appreciated.

I think what you want MySQL date_add () function -

For example, DATE_ADD ('2013-06-22 09:46:00', INTERVAL 1 day), where you can change the date-time and day intervals along with the respective column names.

Update Let us assume, the date time zone is called FIELDA and if the integer field is called FIELDB, represent the day, the function can be called as Is:

  DATE_ADD (FIELDA, interval field day);   

If the integer field represents hour, then you call it:

  DATE_ADD (FIELDA, INTERVAL FIELDB HOUR);   

Hope above helps!

No comments:

Post a Comment