1
<input type = "date" name = "myDate" onchange = ""> //this is input date 

When the user picks a date then it wants to change based on above date How to change based on given date please help me..!

<table class="table table-bordered" id="thbg">

<thead><td></td>

<th>Project</th>

<th>Activity</th>

<th>Bill Type</th>

<?php

$day = "1";
$month = "11";
$year = "2017";

$start_date = $day."-".$month."-".$year;
$start_time = strtotime($start_date);

$end_time = strtotime("+1 week", $start_time);

for($i=$start_time; $i<$end_time; $i+=86400)
{
  print  '<th align="center"> '. date("m-d-Y  l", $i). '</th>';
}
?>
<th>Hours</th>      
</thead>
</table>

And the output is also getting wrong dates, e.g. I am getting two Sundays at a time

this is my wrong output

Can anyone suggest a solution?

Narsimhulu
  • 77
  • 8
  • 1
    Just a comment - your HTML is technically invalid. You should have a `` around all your ``s and ``s - i.e. table cells must be within a table row, which can itself be within a `` or ``, and those must be within a `` element.
    – ADyson Nov 30 '17 at 11:21
  • Yaa i changed my code with , but this is not my solution
    – Narsimhulu Nov 30 '17 at 11:39
  • I know it's not, that's why I made it a comment not an answer :-) – ADyson Nov 30 '17 at 11:40

3 Answers3

1

Not sure what you try to achieve here but a better option would be to use the DateTime Class

something like that should work

$day = "1";
$month = "11";
$year = "2017";
$objDateStart = DateTimeImmutable::createFromFormat('j-m-Y', $day."-".$month."-".$year);
$objDateEnd = $objDateStart->modify('+1 week');

$objDateRange = new DatePeriod($objDateStart, new DateInterval('P1D'), $objDateEnd);
foreach($objDateRange as $objDate)
{
    echo  '<th align="center"> '. $objDate->format("m-d-Y l"). '</th>';
}
Atural
  • 5,389
  • 5
  • 18
  • 35
0
As it is i have executed your code, i am getting proper output without any repeated values. 

echo "<table><thead>

        <th>Project</th>

        <th>Activity</th>

        <th>Bill Type</th>";


        $day = "1";
        $month = "11";
        $year = "2017";

        $start_date = $day."-".$month."-".$year;
        $start_time = strtotime($start_date);

        $end_time = strtotime("+1 week", $start_time);

        for($i=$start_time; $i<$end_time; $i+=86400)
        {
          print   '<th align="center"> '. date("m-d-Y  l", $i). '</th>';
        }
        echo "<th>Hours</th>
        </thead>";
Ayyappa amara
  • 437
  • 3
  • 16
0

The date command is repeating Nov 5th because that was daylight saving time and it's rounding down the hours to 00:00:00.

Try using the datetime object instead.

Here's an answer that loops through a date range with it.

https://stackoverflow.com/a/29765247/3585500

ourmandave
  • 1,505
  • 2
  • 15
  • 49