Page 1 of 1

Date and Time Difference

Posted: Wed Nov 15, 2006 6:08 pm
by winsonlee
How can I find the date and time difference between two days and the two days is calculated during office hours only??

For example :
Official timings are 9.00 am to 6.00 pm
1.only official time is taken into consideration.
2.saturdays and sundays are not considered.


Time IN : 16/11/06 4.00 pm (THURSDAY)
Time OUT : 17/11/06 2.05pm (FRIDAY)
so my answer should be 7 hours and 5 minutes.


Time IN : 17/11/06 3.00pm (FRIDAY)
Time OUT : 21/11/06 11.37pm (TUESDAY)

friday 3 hours
monday 9 hours
tuesday 2 hours 37 minutes
so totally diff is 14 hours and 37 minutes.

anyway i can archieve this ??

Posted: Wed Nov 15, 2006 6:10 pm
by feyd
Calculate the number of days, then add the last days final time minus the start of business.

Posted: Wed Nov 15, 2006 7:48 pm
by RobertGonzalez
If they are in a database, use the databases date functions. If it is MySQL AND you MySQL is version 4.1+, you can use DATEDIFF().

Posted: Wed Nov 15, 2006 10:50 pm
by winsonlee
I believe i cant minus non working hours using mysql statement. can I ??

I manage to get the working hours but these includes the sat and sun.


from 02/11/2006 to 30/11/2006 how can i know that there are 4 sat and 4 sun ??

Posted: Wed Nov 15, 2006 10:57 pm
by feyd
Iterate over the days and determine if they are valid working dates.. or determine the number of full weeks then subtract accordingly.