Calculating time difference between two 24H time in php -


I am struggling to calculate time difference between two 24-hour format. The data extracted from my database is as follows:

  $ timein = "09:00"; $ Timeout = "17:00"; $ Timediff = $ timein - $ Timeout   

As above, how do I get $ timediff = 8 ?

If you set them first in full dates:

  $ timein = "09:00"; $ Timeout = "17:00"; $ Datein = strtotime (date ("Ymd". $ Timein); $ dateout = strtotime (date ("Ymd". $ Timeout);   

Therefore, actually the date that you use (Today's date) can be any other date because it is about the time between all hours. Then you can create php date function:

  $ hourIn = date ("G", $ datein); // = 9 $ hourOut = date ("G", $ dateout); // = 17   

simple Mathematics followed:

  $ diff = $ hour hour - $ hourIn; // = 8    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -