PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 31st, 2004, 03:37 AM
NoOne NoOne is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 NoOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
2 Dates without weekends

Hi,

I have 2 dates with (0000-00-00) format and I want to know how many days between them BUT without satrday and sunday ..

Regards,
NoOne

Reply With Quote
  #2  
Old August 2nd, 2004, 07:20 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
There's probably a more elegant way of doing it, but you could use a combination of mktime() and date() to do this. Use mktime() to create a timestamp for each date in the range and then send the timestamp and the 'w' parameter to the date function to determine whether or not the weekday is between 0 and 5 (Monday and Friday). If so, increment a count.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old August 5th, 2004, 06:52 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,029 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 1 Week 12 h 55 m 59 sec
Reputation Power: 16
Send a message via ICQ to Itsacon
Post

How about something like this?

PHP Code:
function workingdaycount($date1$date2)
{
    
#####    init result value
    
$workdays 0;

    
#####    get unix timestamps (input must be formatted yyyy-mm-dd)
    
$unixdate1 mktime(0,0,0intval(substr($date152)), intval(substr($date182)), intval(substr($date104)));
    
$unixdate2 mktime(0,0,0intval(substr($date252)), intval(substr($date282)), intval(substr($date204)));
    
    
#####    make sure order of stamps is correct
    
if($unixdate2<$unixdate1)
    {
        
$temp $unixdate1;
        
$unixdate1 $unixdate2;
        
$unixdate2 $temp;
    }

    
#####    get time difference
    
$timediff $unixdate2 $unixdate1;

    
$weekseconds 604800;         # 60*60*24*7 = amount of seconds in a week
    
    #####    get number of complete weeks, multiply by 5 for number of working days.
    
$workdays += (floor($timediff $weekseconds));

    
#####    get day of week for both entries (0 => sunday, 6 => saturday)
    
$weekday1 date('w'$unixdate1);
    
$weekday2 date('w'$unixdate2);

    
#####    calculate amount of days in between, weekwise
    
if($weekday1 $weekday2)    # no weekend in between 
    
{
        if(
$weekday2 5)
            
$weekday2 5;
        
$workdays += $weekday2 $weekday1;
    }                
# weekend in between
    
else
        
$workdays += $weekday2 $weekday1;

    
#####    return result
    
return $workdays;



Of course, this can be shortened a lot, but wanted to be clear.
Hope this helps...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > 2 Dates without weekends


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap