Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-28-2007, 05:14 PM
Junior Member
 
Join Date: Aug 2007
Posts: 4
Default Adding only working day

Hi to all.

Is it possible to add to a date only working days?

Example: today is friday and I do a Zend_Date::add for adding 3 days. I want the result to be wednesday of the next week, not monday... Is it possible???

Thanx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-02-2007, 07:13 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

The easiest solution I can think of off the top of my head is to check the weekday and increment if the days are weekends.

ie.
Code:
//pseudocode, I didn't test this, its just concept

function addWorkDays(startDate, numDays) {
    $numDaysPadding = 0;
 
    for ($i = 0; $i < numDays; $i++) {
        if ( $startDate + ($i +1) == "Saturday" ||
              $startDate + ($i +1) == "Sunday")  {
             $numDaysPadding++;
        }       
    }
    $numDays += $numDaysPadding;
    
    return $startDate + $numDays;
}

Essentially, you increment the number of days your adding if you encounter a weekend day. Zend_Date can return the actual day of the week via ->getWeekday(). This returns an int which is mapped to the day of the week:
0 => Sunday
1=> Monday
2 => Tuesday
3 => Wednesday
....
6 => Saturday


hope that helps...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-05-2007, 06:33 AM
Junior Member
 
Join Date: Aug 2007
Posts: 4
Default

Thanx a lot
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-07-2007, 02:55 AM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

Glad to help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:21 PM.