Hi,
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

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? )

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

commented: Each view in what really the questioner think and asking might take away that fog , so share … +9
Member Avatar for diafol

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?

Hi Mr.diafol,
Thanks for that in PHP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.