-2

Help me please...

I want to insert all dates and days name in one year automatically. for example : 2017. I want to insert into table from 01-01-2017 to 31-12-2017 automatically.

st.anger
  • 9
  • 2
  • 1
    Probably use something like [**this**](http://stackoverflow.com/a/4312491/2518525) and loop over the returned data, then insert it into your database. – Darren Jan 11 '17 at 03:23
  • Thx for the link. But How to modify that code if I input only the year in the textfield – st.anger Jan 11 '17 at 03:43

2 Answers2

0

Something like this.

with getFullYear().

for (var d = new Date(2017, 0, 1); d < new Date(2018, 0, 1); d.setDate(d.getDate() + 1)) {
  var input = $("<input>");
  input.val(d.getFullYear());
  $("#year").append(input);

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="year">

</div>
Deep
  • 9,594
  • 2
  • 21
  • 33
0

PHP way to do this:

$startDate = new DateTime('2017-01-01');
$endDate = new DateTime('2018-01-01');

while($startDate < $endDate){
    echo $startDate->format('d-m-Y'); //print date with format day-month-year
    echo "\n";
    $startDate->add(new DateInterval('P1D')); //add 1 day
}

Output:

01-01-2017
02-01-2017
03-01-2017
04-01-2017
...
31-12-2017
Jared Chu
  • 2,757
  • 4
  • 27
  • 38
  • I want to give the days name beside the date. format('d-m-Y'); //print date with format day-month-year echo "   "; echo $day; echo "
    "; $startDate->add(new DateInterval('P1D')); //add 1 day } ?> Why the output is always "Thursday"? Help me please..
    – st.anger Jan 26 '17 at 08:44
  • sorry for late response, could you message me directly via skype: hienboy90 – Jared Chu Feb 06 '17 at 11:02