Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Removing saturdays and sundays
Old 03-03-2008, 05:06 PM Removing saturdays and sundays
Junior Talker

Posts: 3
Name: Jonathan
Trades: 0
Please help me... I want to count 150 + 450 weekdays from a given date. How do I remove the saturdays and sundays?

Thanks for your support...

PHP Code:
 
<?php
$startDate 
'2008-03-02';
$startTime strtotime($startDate);  // convert date to UNIX timestamp integer
$plus150days date('Y-m-d'strtotime('+150 days'$startTime));
$minus450days date('Y-m-d'strtotime('-450 days'$startTime));
echo 
"Start: $startDate<br />+150: $plus150days<br />-450: $minus450days";

Last edited by mgraphic; 03-03-2008 at 06:12 PM.. Reason: Fixed broken code example
sanoj4 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-03-2008, 05:15 PM Re: Removing saturdays and sundays
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
Haha, sorry, i cant help, but that title, it was just to hard to ignore...

However, I do suggest you show us what you've got so far...

It might help someone who's trying to help you.

EDIT: also, why is the code you've posted a link to activate your account? please post the code inside the [code] and [/code] tags.
__________________
Personal UK Webhosting

Please login or register to view this content. Registration is FREE

Last edited by Joshy D; 03-03-2008 at 05:17 PM..
Joshy D is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 05:47 PM Re: Removing saturdays and sundays
Junior Talker

Posts: 3
Name: Jonathan
Trades: 0
Quote:
Originally Posted by Joshy D View Post
Haha, sorry, i cant help, but that title, it was just to hard to ignore...

However, I do suggest you show us what you've got so far...

It might help someone who's trying to help you.

EDIT: also, why is the code you've posted a link to activate your account? please post the code inside the [code] and [/code] tags.
I really donīt know how it could become a link!? Sorry!
sanoj4 is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 06:16 PM Re: Removing saturdays and sundays
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I'm confused. Do you want to count 450 days from start date, or 450 days plus Sat & Sun (which would be 450+ days) from start date?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 12:20 AM Re: Removing saturdays and sundays
Junior Talker

Posts: 3
Name: Jonathan
Trades: 0
I want to count 150 and 450 monday-friday from start date.

Example: Start 080302

day 5: 080307
day 10: 080314
day 15: 080321

and so on....
sanoj4 is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 01:34 AM Re: Removing saturdays and sundays
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
I think you would have to iterate through days, convert each date into unix timestamp and pass it to getdate() to obtain info about what day of week is that date. Then if the given date is sat or sun decrease the working days counter.
PHP Code:
$days 150;
$businessDays $days;
$startDate '2008-03-02';
$startTime strtotime($startDate);
for (
$i 0$i <= $days$i++) {
   
$currentTime strtotime("+{$i} days"$startTime));
   
$currentDay getdate($currentTime);
   if (
in_array($currentDay['wday'], array(0,6)))
      
$businessDays -= 1;

__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-08-2008, 06:11 PM Re: Removing saturdays and sundays
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
I think you would have to iterate through days, convert each date into unix timestamp and pass it to getdate() to obtain info about what day of week is that date. Then if the given date is sat or sun decrease the working days counter.
PHP Code:
$days 150;
$businessDays $days;
$startDate '2008-03-02';
$startTime strtotime($startDate);
for (
$i 0$i <= $days$i++) {
   
$currentTime strtotime("+{$i} days"$startTime));
   
$currentDay getdate($currentTime);
   if (
in_array($currentDay['wday'], array(0,6)))
      
$businessDays -= 1;

sounds like a plan...
a good plan, with lots of potential, why not try it...tell us the result...
__________________
Personal UK Webhosting

Please login or register to view this content. Registration is FREE
Joshy D is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Removing saturdays and sundays
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25031 seconds with 12 queries