This code *should* do something similar to what Phillip suggested.  It
will figure out the correct Sunday based on whether the week is odd or
not, then it will add the correct number of days to get to either next
Saturday or the Saturday after next Saturday.

<?php
if ((date('W') % 2) == 0) {
// week is even, payday is last sunday, find saturday after next
        $payday = date('m/d/y', strtotime('last Sunday')+1123200);
        print 'week is even, pay period is ' . $payday;
} else {
// week is odd, payday is the sunday before last, find next sat.
        $payday = date('m/d/y', strtotime('last Sunday') + 518400);
        print 'week is odd, pay period is ' . $payday;
}
?>

On Mon, 2003-02-03 at 18:15, Philip Hallstrom wrote:
> > I'm writing a quick little thing to act as a time clock since people are
> > writing out by hand and it's not so accurate. It's basically click a button
> > to clock in and click a button to clock out.
> >
> > What I also want to do is create a report (well I've already created the
> > report) but I want to limit it to the current pay period. Our pay periods
> > are biweekly. I was trying to think of a smart way to have php figure out
> > what the current pay period is and I'm having a hard time figuring out if
> > this is even possible or should I just tell it a years worth of pay period
> > ranges for now.
> >
> > I figure something like, if the week # is even, use this past Sunday as the
> > start date. If the week # is odd use the Sunday of the week before. Then
> > figure out what date is 2 saturdays after whatever Sunday was selected.
> 
> That seems very doable... look at the date() function, in particular the
> options to return week number, day of week (0-6), etc.  Then it's just
> some conditionals, and substractions to get back to the right sunday, and
> then add 14 (or is it 13?) days to get the right saturday.
> 
> Just remember to do it all the math as the number of seconds since 1970
> (look at time() and strtotime()) and you'll be fine.
> 
> -philip
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to