## Count number of Sunday's in given Month and year

count number of sundays between two dates sql

tableau count number of sundays in a month

count number of saturdays in a month excel

calculate sundays between two dates

excel count number of mondays in a date range

calculate number of sundays between two dates in java

count number of mondays in a month in excel

I want output to be count of sunday's present in given month and year.

**This is my code:**

$months=$_POST['month']; $years=$_POST['year']; $monthName = date("F", mktime(0, 0, 0, $months)); $fromdt=date('Y-m-01 ',strtotime("First Day Of $monthName $years")) . '<br/>'; $todt=date('Y-m-d ',strtotime("Last Day of $monthName $years")) . '<br/>'; $num_sundays=''; for ($i = 0; $i < ((strtotime($todt) - strtotime($fromdt)) / 86400); $i++) { if(date('l',strtotime($fromdt) + ($i * 86400)) == 'Sunday') { $num_sundays++; } }

I am not getting any output if i echo $num_sundays. Please help me . I am new to PHP

You just need to remove `<br>`

from these two lines:

$fromdt=date('Y-m-01 ',strtotime("First Day Of $monthName $years")) . '<br/>'; $todt=date('Y-m-d ',strtotime("Last Day of $monthName $years")) . '<br/>';

Otherwise this will be the part of start and end date, and your `strtotime()`

will return false.

**Example:**

<?php $months = 12; $years=2016; $monthName = date("F", mktime(0, 0, 0, $months)); $fromdt=date('Y-m-01 ',strtotime("First Day Of $monthName $years")) . '<br/>'; $todt=date('Y-m-d ',strtotime("Last Day of $monthName $years")) . '<br/>'; var_dump(strtotime($todt)); var_dump(strtotime($fromdt)); ?>

**DEMO:** This will return false for both.

**Example 2:**

<?php $months = 12; $years=2016; $monthName = date("F", mktime(0, 0, 0, $months)); $fromdt=date('Y-m-01 ',strtotime("First Day Of $monthName $years")) ; $todt=date('Y-m-d ',strtotime("Last Day of $monthName $years")); var_dump(strtotime($todt)); var_dump(strtotime($fromdt)); ?>

**DEMO:** This will return the values

**Complete Example:**

<?php $months = 12; $years=2016; $monthName = date("F", mktime(0, 0, 0, $months)); $fromdt=date('Y-m-01 ',strtotime("First Day Of $monthName $years")) ; $todt=date('Y-m-d ',strtotime("Last Day of $monthName $years")); $num_sundays=''; for ($i = 0; $i < ((strtotime($todt) - strtotime($fromdt)) / 86400); $i++) { if(date('l',strtotime($fromdt) + ($i * 86400)) == 'Sunday') { $num_sundays++; } } echo "Total Count is: ".$num_sundays; ?>

**DEMO:** This will return 4 sunday

**Count Sundays between two dates,** Excel stores dates as numbers. The numbers shown relate to those two dates. How a date is displayed is determined by the format you apply to� This section will introduce formulas to count the numbers of days except Sunday in a date range in Excel. Please do as follows: Select a blank cell you will return the number of days except Sunday, enter the formula =SUM(IF(WEEKDAY(ROW(INDIRECT(B1&":"&B2)),2)<>7, 1,0)) (B1 is the start date, and B2 is the end date) into it, and press the Ctrl + Shift + Enter keys at the same time.

Get all sunday in month see below code:

function total_sun($month,$year) { $sundays=0; $total_days=cal_days_in_month(CAL_GREGORIAN, $month, $year); for($i=1;$i<=$total_days;$i++) if(date('N',strtotime($year.'-'.$month.'-'.$i))==7) $sundays++; return $sundays; } echo total_sun(11,2016);

**How to count the days excluding Sundays between two dates in ,** Supposing you have two given dates, and now in this tutorial, I tell you how to count the number of days excluding Sundays between these two dates in Excel. Count days excluding Sundays with formula. Here I can introduce a formula for counting days excluding Sundays during a date range. Select a blank cell, here is C2, and type this formula =B2-A2-INT((B2-A2-WEEKDAY(B2)+1)/7) into it, and then press Enter key, a date displayed.

Without loop. I hope this gives the correct results.

date_default_timezone_set('UTC'); // unix timestamp 0 = Thursday, 01-Jan-70 00:00:00 UTC // unix timestamp 259200 = Sunday, 04-Jan-70 00:00:00 UTC $sun_first = strtotime('1970-01-04'); $t1 = strtotime('2018-10-01') - $sun_first - 86400; $t2 = strtotime('2018-10-31') - $sun_first; $sun_count = floor($t2 / 604800) - floor($t1 / 604800); // total Sunday from 2018-10-01 to 2018-10-31 echo $sun_count; // 4

**Excel formula: Count day of week between dates,** To count weekdays (Mondays, Fridays, Sundays, etc.) At the core, this formula uses the WEEKDAY function to test a number of dates to see if they land on a� Microsoft Excel features many functions to help users count the number of business days between two dates or find the start and end dates of a project given a set number of business days. These functions are handy for planning and when writing proposals to determine the timeframe of a project.

Check following Example. I work perfectly..

function dayCount($day,$month,$year){ $totalDay=cal_days_in_month(CAL_GREGORIAN,$month,$year); $count=0; for($i=1;$totalDay>=$i;$i++){ if( date('l', strtotime($year.'-'.$month.'-'.$i))==ucwords($day)){ $count++; } } echo $count; } dayCount('saturday',3,2019);

**How to Calculate Number of Weekends between Two Dates in Excel ,** How to count the number of Sundays between two dates with a formula in Excel. Calculate the Number of Weekdays between Two Dates� If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates. It counts the number of Sundays between date1 and date2. DateDiff counts date2 if it falls on a Sunday; but it doesn't count date1, even if it does fall on a Sunday.

working example dorcode calculation

$startd="31-7-2006 15:30:00"; $endd="31-7-2007 15:30:00"; $startDate=$startd; $endDate=$endd; $startDate1 = strtotime($startDate); $endDate1 = strtotime($endDate); if($startDate1>$endDate1) { $startDate1 = strtotime($endDate); $endDate1 = strtotime($startDate); } else { $startDate1 = strtotime($startDate); $endDate1 = strtotime($endDate); } $p=0; for($i = strtotime("Sunday", $startDate1); $i <= $endDate1; $i =strtotime('+1 week', $i)) { $p++; echo $p.": ".date('F d, Y', $i)."<br>"; }

**Calculate number of sundays, saturdays between two dates,** How to calculate number of sundays, saturdays and other dates between two dates in Excel, to Duration: 3:58
Posted: Aug 5, 2015 Working from the inside out, the WEEKDAY function is configured with the optional argument 2, which causes it to return numbers 1-7 for the days Monday-Sunday, respectively. This makes it easier to list the days in order with the numbers in column E in sequence. WEEKDAY then evaluates each date in the named range "dates" and returns a number.

**Calculate number of Sundays in the month,** Try this where A1 is the starting day of the month: =SUMPRODUCT(N(TEXT( ROW(INDIRECT(A1&":"&EOMONTH(A1,0))),"ddd")="Sun")). You can also use this� Count Workdays excluding Holidays and Weekends (Saturday & Sunday) The function NETWORKDAYS is used while counting the total number of workdays in Excel.While counting the workdays using this function Saturdays and Sundays are considered as weekends by default.

**How Many Days Calculator - count days in a year,** Select any day of the week and you can calculate how many times that day occurs in any given year. This site provides a tool to count the number of any selected day of the week over an entire year. You can how many Sundays in 2020 Date: Total Traveler Throughput: Total Traveler Throughput (1 Year Ago - Same Weekday) 7/22/2020: 570,951: 2,561,911: 7/21/2020: 530,421: 2,499,460: 7/20/2020: 695,330

**Number of sundays between two dates,** I need to calculate the number of Sundays between two dates in Excel. I have looked at the NETWORKDAYS function, but it omits weekends. Bonus Tip: Count Mondays in the date range. Remember that WEEKDAY returns a number for each day of the week. In order to count Mondays or some other weekday in the date range remember these numbers for each weekday: 1 = Sunday, 2 = Monday, 3= Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, 7 = Saturday

##### Comments

`strtotime($todt)`

is empty- remove this
`. '<br/>'`

from both lines and chk the result - I think too it is empty
- @devpro hey thnx man.. Itworks well now. +1
- glad to help u friend, u can check the complete example below, and dont forgot to accept the correct answer this will help to future visitors.
- This is not correct. For example: It returns 4 for 2018 September (9) But that month has 5 Sundays
- Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.