MySQL Forums
Forum List  »  PHP

Given Time-In & Time-Out, Get Hours & Minutes That Fall Between 22:00 and 06:00 the FF day
Posted by: Jeff Martin
Date: January 13, 2021 08:14AM

Good day Everyone!

I have two fields: Time-In(datetime) and Time-Out(datetime).

How can I get the number of hours and minutes that fall between 10pm(22:00) and 6am(06:00) the following day?

Examples:
Time-In:'2021-01-12 08:00:00', Time-Out:'2021-01-12 17:00:00' => 0 hrs, 0 mins
Time-In:'2021-01-12 16:00:00', Time-Out:'2021-01-13 00:00:00' => 2 hrs, 0 mins
Time-In:'2021-01-12 21:00:00', Time-Out:'2021-01-13 02:50:00' => 4 hrs, 50 mins
Time-In:'2021-01-12 00:00:00', Time-Out:'2021-01-12 08:00:00' => 6 hrs, 0 mins

What I have in mind is using UNIX_TIMESTAMP() and TIMESTAMPDIFF() to get the seconds that falls between 10pm and 6am but I don't know how exactly to do it.

Can anyone guide me what to do? Thank you very much

Options: ReplyQuote


Subject
Written By
Posted
Given Time-In & Time-Out, Get Hours & Minutes That Fall Between 22:00 and 06:00 the FF day
January 13, 2021 08:14AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.