473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP date/time questions

Mike Kypriotis
I have a program keeping the shifts of workers (e.g. at 12/1/2012 X worker worked the 8:00-16:00 shift). Shifts duration is variable meaning that the admin defines its duration so a couple of questions
a) How can i calculate the hours in each shift? (the shifts start/end either at :00 or :30 e.g. 8:00-16:30 or 16:30-18:30) meaning that 16:30-18:00 is 1 and a half hour (or 3 halfs of hour -which is the format i will be saving it) or 8:00-16:00 is 16*30min. Note that shifts like 16:00-1:00 or 20:00-03:00 also exists.
b) given that in my database i have how many hours of each day each worker worked, i wanna check how many hours a given worker worked this week (do not want each worker to pass the 40h a week limit)
any ideas?
Jul 19 '12 #1
2 1290
Luuk
1,047 Expert 1GB
This will calculate the number of half-hours are between start and end:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     function halfhours($from,$to) {
  3.         $u1=substr($from,0,2);
  4.         $m1=substr($from,3,2);
  5.         $u2=substr($to,0,2);
  6.         $m2=substr($to,3,2);
  7.  
  8.         echo "$u1:$m1 $u2:$m2 \n";
  9.         $d = ($u2-$u1)*2;
  10.         if ($d<=0) { $d=$d+48; }
  11.         if ($m1==30) { $d = $d-1; }
  12.         if ($m2==30) { $d = $d+1; }
  13.  
  14.         return $d;
  15.     }
  16.  
  17.     $from="16:30";
  18.     $to="18:00";
  19.     echo "Number of half-hours between $from and $to is: ".halfhours($from,$to)." <br>\n";
  20.  
  21.     $from="20:00";
  22.     $to="03:00";
  23.     echo "Number of half-hours between $from and $to is: ".halfhours($from,$to)." <br>\n";
  24. ?>
  25.  
To calculatie how many hours someone has worked more info is needed.
Probably you are storing this in a database?
Jul 21 '12 #2
Why not just use the time() function and figure out your hours from the seconds.
Jul 23 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
5
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
6
by: Mark Reed | last post by:
Hi Guru's, I have created a database to monitor hours I have worked as our payroll department are so crap. I work nights most of the time but occasionally I have to work on days. Between the hours...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
12
by: addicdid2003 | last post by:
OK, I am fairly new to Vb, and I am doing a project for school... Does anyone know how to calculate a date, based on the date selected in the Date/Time Picker, and have it display in another text box?
8
by: Killer42 | last post by:
Hi all. I have an interesting situation; searching a Date field for my exact value fails, but including it in a range works. I know this sounds like the usual beginner's date/time woes but I...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
1
by: Thierry Lam | last post by:
I have a python time string which has the following value: 1225137896 The above corresponds to 2008/10/27 16:04:56 What can I use to convert 1225137896 to a more readable date, time format?
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.