php weeks between 2 dates

php date
php date difference in months
get all weeks between two dates php
php date_diff
how to get difference between two date and time in php
php calculate time difference between two dates in minutes
php date difference in hours
php weekdays between two dates

hi how to find no of weeks and each mondays date between 2 dates. for ex 10-07-2009 to today .

Note :consider leap year and other date related constrains also.


echo datediff('ww', '9 July 2003', '4 March 2004', false);

Find the function on the site below: http://www.addedbytes.com/code/php-datediff-function/

UPDATE

Link is now broken (Sept 2017), so function below pulled from webarchive:

<?php

/**
 * @param $interval
 * @param $datefrom
 * @param $dateto
 * @param bool $using_timestamps
 * @return false|float|int|string
 */
function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
{
    /*
    $interval can be:
    yyyy - Number of full years
    q    - Number of full quarters
    m    - Number of full months
    y    - Difference between day numbers
           (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
    d    - Number of full days
    w    - Number of full weekdays
    ww   - Number of full weeks
    h    - Number of full hours
    n    - Number of full minutes
    s    - Number of full seconds (default)
    */

    if (!$using_timestamps) {
        $datefrom = strtotime($datefrom, 0);
        $dateto   = strtotime($dateto, 0);
    }

    $difference        = $dateto - $datefrom; // Difference in seconds
    $months_difference = 0;

    switch ($interval) {
        case 'yyyy': // Number of full years
            $years_difference = floor($difference / 31536000);
            if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
                $years_difference--;
            }

            if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
                $years_difference++;
            }

            $datediff = $years_difference;
        break;

        case "q": // Number of full quarters
            $quarters_difference = floor($difference / 8035200);

            while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                $months_difference++;
            }

            $quarters_difference--;
            $datediff = $quarters_difference;
        break;

        case "m": // Number of full months
            $months_difference = floor($difference / 2678400);

            while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                $months_difference++;
            }

            $months_difference--;

            $datediff = $months_difference;
        break;

        case 'y': // Difference between day numbers
            $datediff = date("z", $dateto) - date("z", $datefrom);
        break;

        case "d": // Number of full days
            $datediff = floor($difference / 86400);
        break;

        case "w": // Number of full weekdays
            $days_difference  = floor($difference / 86400);
            $weeks_difference = floor($days_difference / 7); // Complete weeks
            $first_day        = date("w", $datefrom);
            $days_remainder   = floor($days_difference % 7);
            $odd_days         = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?

            if ($odd_days > 7) { // Sunday
                $days_remainder--;
            }

            if ($odd_days > 6) { // Saturday
                $days_remainder--;
            }

            $datediff = ($weeks_difference * 5) + $days_remainder;
        break;

        case "ww": // Number of full weeks
            $datediff = floor($difference / 604800);
        break;

        case "h": // Number of full hours
            $datediff = floor($difference / 3600);
        break;

        case "n": // Number of full minutes
            $datediff = floor($difference / 60);
        break;

        default: // Number of full seconds (default)
            $datediff = $difference;
        break;
    }

    return $datediff;
}

PHP Date Exercise: Calculate weeks between two dates, php function week_between_two_dates($date1, $date2) { $first = DateTime::createFromFormat('m/d/Y', $date1); $second = DateTime::createFromFormat('m/d/Y', $date2); if($date1 > $date2) return week_between_two_dates($date2, $date1); return floor($first->diff($second)->days/7); } $dt1 = '1/1/2014'; $dt2 = '12/31/2014'; The Duration Calculator calculates the number of days, months and years between two dates.


Here's an alternative solution using DateTime:-

function datediffInWeeks($date1, $date2)
{
    if($date1 > $date2) return datediffInWeeks($date2, $date1);
    $first = DateTime::createFromFormat('m/d/Y', $date1);
    $second = DateTime::createFromFormat('m/d/Y', $date2);
    return floor($first->diff($second)->days/7);
}

var_dump(datediffInWeeks('1/2/2013', '6/4/2013'));// 21

See it working

PHP: Calculate the difference in weeks between two dates., For example: If there are 125 days between two dates, then that is 17.85 weeks. By default, our floor function will round that decimal figure down to 17. php weeks between 2 dates. Ask Question Asked 9 years, 6 months ago. Active 16 days ago. Viewed 49k times 34. 10. hi how to find no of weeks and each mondays date


$diff = strtotime($dateto, 0) - strtotime($datefrom, 0);
echo floor($diff / 604800);

date_diff - Manual, A mathematical decimal difference between two informed dates 2. tuxedobob � . 5 years ago. Even the top rated comment here, Sergio Abreu's, doesn't treat� This calculator determines number of weeks between two given dates person_outline Timur schedule 2018-02-26 22:58:16 This simple calculator determines the number of weeks between first date and second date.


The following function computes the "spoken weeks" between two timestamps (i.e. monday is next week if you are on saturday).

function days_between($datefrom,$dateto){
    $fromday_start = mktime(0,0,0,date("m",$datefrom),date("d",$datefrom),date("Y",$datefrom));
    $diff = $dateto - $datefrom;
    $days = intval( $diff / 86400 ); // 86400  / day

    if( ($datefrom - $fromday_start) + ($diff % 86400) > 86400 )
        $days++;

    return  $days;
}

function weeks_between($datefrom, $dateto)
{
    $day_of_week = date("w", $datefrom);
    $fromweek_start = $datefrom - ($day_of_week * 86400) - ($datefrom % 86400);
    $diff_days = days_between($datefrom, $dateto);
    $diff_weeks = intval($diff_days / 7);
    $seconds_left = ($diff_days % 7) * 86400;

    if( ($datefrom - $fromweek_start) + $seconds_left > 604800 )
        $diff_weeks ++;

    return $diff_weeks;
}

PHP Calculate Weeks between 2 dates - PHP, PHP Script calculates that 2 weeks have passed since that date and redirects me to page2.html. There are 40 pages in total, so the script can redirect me to up to� Two PHP functions are used in the above script to get the number of days between two dates. date_create() – This function returns a new DateTime object. date_diff() – This function returns the difference between two DateTime objects.


This work great

function weeks_between($datefrom, $dateto)
    {
        $datefrom = DateTime::createFromFormat('d/m/Y H:i:s',$datefrom);
        $dateto = DateTime::createFromFormat('d/m/Y H:i:s',$dateto);
        $interval = $datefrom->diff($dateto);
        $week_total = $interval->format('%a')/7;
        return floor($week_total);

    }

weeks_between("25/02/2000 11:30:00","05/06/2015 11:29:59")

How to calculate the number of weeks between two dates in php , How to calculate weeks between 2 dates in php? How to calculate the difference between two dates in PHP? How to get all the week numbers� Given two dates, start_date and end_date. The task is to find the difference between two dates. Examples: Input: start_date: 2016-06-01 22:45:00 end_date: 2018-09-21 10:44:01 Output: 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds Input: start_date: 2015-05-12 12:37:30 end_date: 2018-04-25 12:45:31 Output: 2 years, 11 months, 19 days, 0 hours, 8 minutes, 1 seconds


How to calculate the difference between two dates in PHP , Method 2: To use date-time mathematical formula to find the difference between two dates. It returns the years, months, days, hours, minutes,� Use this calculator to work out interest due or earned for a number of days, weeks, months or years or between two specific dates Warning: It is necessary to enable JavaScript for full calculator functionality.


PHP, PHP | Number of week days between two dates. 20-10-2018. You are given two string (dd-mm-yyyy) representing two date, you have to find number of all� From and including: Friday, July 31, 2020 To, but not including Friday, July 31, 2020. Result: 0 days. It is 0 days from the start date to the end date, but not including the end date.


How many weeks between two dates, Hi there, How can I count the number of weeks between 2 dates? Let's say the first date is Jun-10-2002 and the second is Jun-24-2002. To calculate the number of CALENDAR MONTHS (as also asked here) between two dates, I usually end up doing something like this. I convert the two dates to strings like "2020-05" and "1994-05", then get their respective result from the below function, then run a subtraction of those results. /** * Will return number of months.