Jump to content

Dates


johnsmith153

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.