Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trying to determine how many 'selling' days left in a month

Posted on 2013-10-26
7
Medium Priority
?
358 Views
Last Modified: 2013-10-26
Hi,
Our business isn't open on Sundays. In my app I need to show how many selling days are left in the month (days we are open). Currently you can show how many days left in a month using something  like this:
<?php echo date('t') - date('j');?>

But how could I take into account Sundays?
0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39602528
Here you go:

<?php
$start = new DateTime(); //get today
$end = new DateTime('last day of this month'); //get the end of the month
$days = $start->diff($end, true)->days; //number of days between now and the end of the month
$sundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7); //number of sundays

$sellingDays = $days - $sundays; //number of days minus the Sundays

printf("The are %d selling days left this month", $sellingDays);
?>

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
ID: 39602623
Sorry, I don't suppose you know how to implement the above in php5.2?
'last day of this month' for example doesn't work unless its 5.3 and above and I can't upgrade the machine unfortunately....
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39602648
Not really. Don't have access to 5.2 any more!

The diff() method is also >=5.3.

You really ought to upgrade your system though - for security reasons if nothing else. If this is a hosted platform, then chase them up (or change providers)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39602652
Hmmm. Thought a little more and maybe try this. We don't actually need the date of the end of the month, just the day number, which you can get with format('t'):

$start = new DateTime();
$days = $start->format('t') - $start->format('d');
$sundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7);

$sellingDays = $days - $sundays;
printf("The are %d selling days left this month", $sellingDays);

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
ID: 39602654
Great trying it now...
0
 
LVL 1

Author Comment

by:tjyoung
ID: 39602662
Awesome, that did the trick! I appreciate you taking another look Chris.
Thanks again,
Todd
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39602670
No worries ;)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question