First, an entry in the database:

![enter image description here](https://i.stack.imgur.com/ahcr5.png)

I have an input form that writes start date, start and end times (in hour and minute) of working days plus lunch break in minutes (in the example dato=date, modetime=start hour, modeminut=start minute, fyrtime=end hour, fyrminut=end minute). I need to do several calculations: 

* First calculate the date, start hour and minute into the datetime field modetid.
* The do a similar calculation with the end hours and minutes, but move the date up one day if end hours is less than start hour (lets call it fyrtid)
* And finally calculate the difference between fyrtid and modetid minus the pause minutes.

Can it be done directly and automatically in the database (if yes, how) or do I need some PHP to do it (and again, if yes, how)?

I know its a tall order but I have not been able to find much information on date/time calculations that made much sense on my low level of knowledge. Any link to a comprehensive guide on date/time calculation in MySQL or PHP would also be greatly welcomed.