PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
winsonlee
Forum Commoner
Posts: 76 Joined: Thu Dec 11, 2003 8:49 pm
Post
by winsonlee » Wed Nov 15, 2006 6:08 pm
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 ??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 6:10 pm
Calculate the number of days, then add the last days final time minus the start of business.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Nov 15, 2006 7:48 pm
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().
winsonlee
Forum Commoner
Posts: 76 Joined: Thu Dec 11, 2003 8:49 pm
Post
by winsonlee » Wed Nov 15, 2006 10:50 pm
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 ??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 10:57 pm
Iterate over the days and determine if they are valid working dates.. or determine the number of full weeks then subtract accordingly.