johnsmith153 Posted February 11, 2010 Share Posted February 11, 2010 I have a date for the start of the first payroll pay period (7th March 2009). The pay period runs every 2 weeks. $startFirstPeriod = "1236384000"; Can I calculate the most recent and the current pay period based on this. I.e first pay period would be Sat 7th - Fri 20th March 2009. Current period = Sat 30th Jan - Fri 12th Feb 2010. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted February 11, 2010 Share Posted February 11, 2010 Yes but we need to know what your metrics are for determining a pay period. A time stamp is measured in seconds so you can convert the difference between two time stamps into days or add time in increments if days. Ex... 60 seconds in one minute, 60minutes in one hour and 24 hours in a day. 60*60*24=86400 seconds or one day. Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted February 11, 2010 Author Share Posted February 11, 2010 Time period midnight to midnight. All I need is to find the start of previous and current the time period (at midnight). $startValue = time-stamp value at midnight at start of first period will then output the time-stamp value at midnight at the start of the (a) previous and (b) current period. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted February 12, 2010 Share Posted February 12, 2010 Ok in order to pull off what you want to do with the dates, it is going to be relatively complex at least in my mind I am working through it now. I know we will need to use strtotime() along with date() in order to get the future dates we want. To help me visualize this can you give me some example dates to work with and what the expected out come would look like. Then I should be able to come up with a formula that will parse the dates the way you want. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 12, 2010 Share Posted February 12, 2010 Its not all that complicated. We start with what you have - the first period. We take that and conver it to a plain m-d-Y Then we explode it so we can use it as parts in mktime. which we set to midnight but you can easily alter the H:M:S: But once we reach this point and have $thedate you got it licked any way you want. Then we put that into a string to time. Which a pretty powerful animal. look at the PHP manual to see all the goodies you can use along with $thedate. Here we simply add two weeks to $thedate. Fairly easy once you understand how all the convoluted parts fit together. $startFirstPeriod = "1236384000"; $SFPdate = strftime("%m-%d-%Y",$startFirstPeriod);//03-06-2009 list($month,$day,$year)=explode("-",$SFPdate); $thedate = date('m/d/Y h:i:s A', mktime(0, 0, 0, $month, $day, $year));//h,m,s,mo,d,y echo date("Y-m-d H:i:s",strtotime("$thedate +2 week")); HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
yozyk Posted February 12, 2010 Share Posted February 12, 2010 I am not sure that I understood you, but try this code date_default_timezone_set('Europe/London'); $PERIOD = 1209600; $firstPreiodStart = 1236384000; $firstPreiodEnd = $firstPreiodStart + $PERIOD; $today = time(); $pElapse = floor(($today-$firstPreiodStart)/$PERIOD); $curPeriodStart = $firstPreiodStart + $pElapse*$PERIOD; $curPeriodEnd = $curPeriodStart + $PERIOD; echo 'firstPreiodStart: ',date('d.m.Y H:i:s',$firstPreiodStart),'<br/>'; echo 'firstPreiodEnd: ', date('d.m.Y H:i:s',$firstPreiodEnd),'<br/>'; echo 'curPeriodStart: ', date('d.m.Y H:i:s',$curPeriodStart),'<br/>'; echo 'curPeriodEnd: ', date('d.m.Y H:i:s',$curPeriodEnd),'<br/>'; echo 'today: ', date('d.m.Y H:i:s',$today),'<br/>'; Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted February 12, 2010 Author Share Posted February 12, 2010 yozyk - perfect! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.