heres one for all you php array lovers

2 replies
heres my array output

Array (
[0] => Array ( [date] => 2013-01-28 [diff] => 28800 )
[1] => Array ( [date] => 2013-01-29 [diff] => 21602 )
[2] => Array ( [date] => 2013-01-30 [diff] => 14400 )
[3] => Array ( [date] => 2013-01-30 [diff] => 16800 )
[4] => Array ( [date] => 2013-01-31 [diff] => 10800 )
[5] => Array ( [date] => 2013-01-31 [diff] => 27600 )
[6] => Array ( [date] => 2013-02-01 [diff] => 7233 )
[7] => Array ( [date] => 2013-02-01 [diff] => 7205 )
[8] => Array ( [date] => 2013-02-01 [diff] => 12605 )
)

my end result is the following

Regular Time = this one i need to add up each days total diff up to 28800 per day
OT Time = this one i need to add up any time over 28800 each day and anything from reg time is over 144000
Total Time = this one is just reg and OT added together.

my issue is i can not figure out how to add days together. like you will see multiple entries for 30th, 31st and 1st.

these times should be added to give me total time for that day.

the way i see it is i need to add the days times up first then do the calculations for each day to get the total time.

then i need to add up all times under 28800 each day OT get regular time up to 144000

then i need to add up any time over 144000 and anything over 28800 each day.

this would give em the end results for reg, to and total times.

basically the formula i have to work with is the following.

reg time is up to 28800 seconds per day and up to 144000 regular seconds per week.

OT is anything over 28800 seconds per day an anything over 144000 per week

total is reg and OT combined.

any help here would be greatly helpful.
#array #lovers #php
  • Profile picture of the author Lovelogic
    Convert all date+/times to seconds with the PHP command strtotime()
    Do your math...
    Then if needed convert it back using date() into a form humans can understand.


    {{ DiscussionBoard.errors[7687567].message }}
  • Profile picture of the author rft16
    Yes you are right. First you need to add up 'diff' for each date and store it in a new array.

    It should be something like - array( [date] => [total diff] , ... )

    Now, assuming by 144000s/week you are saying ( 28800s/day x 5days ), you can approach it this way:

    loop through each date and check if 'total diff' is > 28800

    -on true add 28800 to 'regular time' and ('total diff' - 28800 ) to 'OT time'.

    -on false simply add the 'total diff' to 'regular time'

    once the loop completes you will have the total 'regular' and 'OT' time. add them up and you have the 'total' time.

    hope this helps
    {{ DiscussionBoard.errors[7691091].message }}

Trending Topics