I do not know about this.

In a table I have from_date and to_date only. I will pass two dates to compare from_date and to_date .
I want all the dates with day in between two days.

My query is SELECT * FROM tbl_name WHERE fromdate>='2015-11-01' AND todate <='2015-11-30'
I need like:
From_date ='2015-11-01' and to_date='2015-11-30
2015-11-01 Sunday
2015-11-02 Monday
2015-11-03 Tuesday
2015-11-3 Monday

1 Year
Discussion Span
Last Post by pritaeas

What has to do that SQL query ? Do you just need to know the dates between two dates (that you could just do with PHP) or do you need to retrieve each date that are among them as a different result set from the DB ? (because I guess that is the second one what data type is the fromdate and todate? )

Edited by jkon


--- EDIT ---
never mind, jkon's questions are more pertinent to solve this.

Edited by cereal

Votes + Comments
Each view in what really the questioner think and asking might take away that fog , so share …

Adapted from manual: http://php.net/manual/en/class.dateperiod.php#109846

function getDates($from,$to,$format)
    $begin = new DateTime($from);
    $end = new DateTime($to);
    $end = $end->modify('+1 day');

    $interval = new DateInterval('P1D');
    $daterange = new DatePeriod($begin, $interval, $end);
    $output = [];

    foreach ($daterange as $date)
        $output[] = $date->format($format);

        return $output;

echo "<pre>";
print_r(getDates('2015-01-01', '2015-01-20', 'Y-m-d, l'));
echo "</pre>";

If you just want consecutive days/dates between two dates.


Each view in what really the questioner think and asking might take away that fog

True, but I thought in this case we needed more straight answers. Anyway, I was wondering about which date to display in the result set, about column type, date format (in case dates were saved with day name and eventual warnings due to truncated incorrect datetime value...) or if the OP was simply asking to output the day name, which can be done through the DAYNAME() function. For example:

> select CONCAT(DATE(NOW()), ' ', DAYNAME(NOW())) AS 'result';
| result              |
| 2015-11-12 Thursday |
1 row in set (0.00 sec)

Hi Mr.Cereal,
Thanks for that. For single date it is ok. But for two dates, how to do?

Edited by AntonyRayan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.