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

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -