Calculate days in between given start date and end date in php

pihu

I have $start_date & $end_date.

I need to find out number of days with name's of days.

I tried following code snipet :

$start_date = '20-07-2012';
$end_date = '22-07-2012';
$start = strtotime($start_date);
$end = strtotime($end_date);
$interval = 2;
$out='';
$int = 24*60*60*$interval;
for($i= $start;$i<= $end; $i += $int ){

    echo date('d-m-Y',$i).'<br />';
}

output :

28-11-2014
30-11-2014

But my expected out is like :

28-11-2014 => friday
30-11-2014 => saturday

let me know what should be php code to yeild the expected output.

WeTheBrains
   // $array[desc:day count starting w 1][desc: 'date' or 'day'];
   // $array[2]['day'];
<?php
$start = '27-11-2014';
$end = '1-12-2014';
    function date_difference($start, $end)
    {
        $first_date = strtotime($start);
        $second_date = strtotime($end);
        $offset = $second_date-$first_date; 
        $result = array();
        for($i = 0; $i <= floor($offset/24/60/60); $i++) {
            $result[1+$i]['date'] = date('d-m-Y', strtotime($start. ' + '.$i.'  days'));
            $result[1+$i]['day'] = date('l', strtotime($start. ' + '.$i.' days'));
        }
        echo '<pre>';
        print_r($result);
        echo '</pre>';
    }
    date_difference($start, $end);
?>

result

Array
(
    [1] => Array
        (
            [date] => 27-11-2014
            [day] => Thursday
        )

    [2] => Array
        (
            [date] => 28-11-2014
            [day] => Friday
        )

    [3] => Array
        (
            [date] => 29-11-2014
            [day] => Saturday
        )

    [4] => Array
        (
            [date] => 30-11-2014
            [day] => Sunday
        )

    [5] => Array
        (
            [date] => 01-12-2014
            [day] => Monday
        )

)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

get monthwise working days between a given start date and end date

MYSQL - Calculate days in the current month between start date and end date

Calculate duration in days between start and end date for each year

How to calculate to an end date given only a start date (calendar) and number of days to increment using java version 1.8?

How to calculate total days between start date & end date in SAPUI5?

Days count across the months with given start date and end date

Given number of days and date then find the start or end date in python

How to calculate start-date from end date and number of days

calculate end date using start date and number of days in Mule 4

calculate start date and end date from given quarter SQL

Split days between 2 given dates into specific batch size and get the start and end_date accordingly

R: Expand rows according to start and end date and calculate hours between days

How to get the number of days between start date and end date of a calendar

Determining if date is between start/end dates, and averaging days since start

Mongoose query between Start Date and End Date of a given collection

Rails: Calculate days between date range given in string format

Calculate start and end date for the given week number in particular month in angular

Date difference between end date to start date

financial year array between start date and end date php

Calculate end date based on start day, no of session, Days Interval (Regular, alternate days)

How do I calculate % of task's completion given start date, end date, and TODAY()

Calculate start date and end date when Fiscal year and Quarter numbers are given

How can I load all week days, between a start date and an end date, to a Data Frame?

start date and end date between two dates

Create column of start date and end date from given date record

Given start date and end date, reshape/expand data for each day between (each day on a row)

How to add missing data entries in an array between a given start date and end date

(javascript or/and datejs)Trying to calculate two dates intervals total salary. when start date and end date has some fraction days of month

get date between start date to end date in php month wise count

TOP Ranking

HotTag

Archive