0

I have a table named leaves.

----------
    id  FromDate    ToDate
    1  20-01-2019    22-01-2019
    2  15-01-2019    22-01-2019
    3  13-01-2019    20-01-2019

I want all dates between each column.

Can anyone help?

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
  • Can you post an example of what your output should look like? Can you also please add what you have already tried/what specifically is going wrong? – morgan121 Jan 22 '19 at 06:00
  • If you want to do with mysql you need a calendar table with all dates or procedure. It can't be done by query. Or do in php – splash58 Jan 22 '19 at 06:00
  • @RAB `select leaves.id,leaves.LeaveType,leaves.ToDate,leaves.FromDate,leaves.Description,DATE_FORMAT(leaves.PostingDate, '%Y-%m-%d') PostingDate,DATE_FORMAT(leaves.PostingDate, '%H:%i:%s') PostingTime, leaves.AdminRemark, DATE_FORMAT(leaves.AdminRemarkDate, '%Y-%m-%d') AdminRemarkDate,DATE_FORMAT(leaves.AdminRemarkDate, '%H:%i:%s') AdminRemarkTime,leaves.leave_status,leaves.emp_id,employee.* FROM leaves JOIN employee ON leaves.emp_id = employee.emp_id WHERE leaves.leave_status = 1 AND DATE_FORMAT(CURDATE(),'%d-%m-%Y') BETWEEN $start AND $end` –  Jan 22 '19 at 06:05
  • This Question Already Answered Find Out Here.. https://stackoverflow.com/questions/2490173/how-to-get-the-number-of-days-of-difference-between-two-dates-on-mysql – Dimpy Dhiman Jan 22 '19 at 06:42
  • @muhammed shanid in future please just edit your question with relevant information, dont put it in the comments. What you have there is basically unreadble – morgan121 Jan 22 '19 at 11:26

2 Answers2

0

You can try below using datediff() function

select id, fromdate, todate,datediff(ToDate,fromdate) as days
from tablename
Fahmi
  • 37,315
  • 5
  • 22
  • 31
0

If you want to do it in your php code then you can do it by finding day count between two days and loop it to get the all dates between that two dates.

<?php

$date1 = "2019-01-13";
$date2 = "2019-01-20";

$date1 = strtotime("2019-01-13");
$date2 = strtotime("2019-01-20");
$datediff = $date2 - $date1;

$days = round($datediff / (60 * 60 * 24));

for($i=1;$i<=$days;$i++){
    echo $date1 = date('d-m-Y', strtotime($date1 . ' +1 day'));echo '   <br>   ';
}
Yogendrasinh
  • 895
  • 1
  • 8
  • 23