Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

Thread: finding total weekends for the current year

1. finding total weekends for the current year

hi,
how can i get total weekends falling in the current year

Thanks
Bhakti Thakkar

• The best I could come up with ...

But you need to really define what a weekend is.
Both Saturday and Sunday, or count one of those days as a weekend?

Same with days,
01/01/2006 --> 12/31/2006 or 01/01/2006 --> 01/01/2007
How you specify one year could end up adding 1 extra weekend.

It all depends on how you look at it.

PHP Code:
``` <?php \$date1="01/01/2006"; \$date2="12/31/2006"; \$days_between=dateDiff("/", \$date2, \$date1); \$weekends=\$days_between/7; echo "Days Between Dates: \$days_between"; echo "<br><br>"; echo "Weekends: \$weekends"; function dateDiff(\$dformat, \$endDate, \$beginDate) { \$date_parts1=explode(\$dformat, \$beginDate); \$date_parts2=explode(\$dformat, \$endDate); \$ts1=mktime(0, 0, 0, \$date_parts1[0], \$date_parts1[1], \$date_parts1[2]); \$ts2=mktime(0, 0, 0, \$date_parts2[0], \$date_parts2[1], \$date_parts2[2]); \$difference = \$ts2-\$ts1; \$diffday = \$difference/86400; \$startday=date(w,\$ts1); //day of week \$endday=date(w,\$ts2); //day of week // do some calculations here on whether or not the first day is // Sunday (therefore, considered a full weekend? // You'll have to determine what you want to count as a weekend. // (Sunday=0, Saturday=6) // Same with the last day, what if Dec 31 is a Saturday? return \$diffday; } ?> ```

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•