-5

If I give 2 dates, I need results as follow -

SUNDAY = 3 TIMES
MONDAY = 3 TIMES
TUESDAY = 4 TIMES
WEDNESDAY = 4 TIMES
THURSDAY = 4 TIMES
FRIDAY  = 4 TIMES
SATRUDAY = 4 TIMES

I am confused if this can be done via any function in mysql or I have to do it from php. I tried with various ways in mysql but could not get any success. I am trying it in php but the codes is somewhat getting lengthy.

Kara
  • 6,115
  • 16
  • 50
  • 57
Obhaso
  • 449
  • 1
  • 4
  • 14
  • 2
    Please show what you have tried. We do not write code for you for free. – kapa Aug 11 '12 at 10:06
  • also your problem is not explained at all – Leon Kramer Aug 11 '12 at 10:09
  • Please refer to [whathaveyoutried.com](http://whathaveyoutried.com) for information on how to better post a question. I have no idea what it is you want. – Michael Aug 11 '12 at 10:12
  • I appology for not following rules while posting questions..and thank you so much for the advice. I will surely take these into considerations while posting questions. :-) – Obhaso Aug 11 '12 at 10:53

1 Answers1

1

Try;

define('ONE_WEEK', 604800); // 7 * 24 * 60 * 60

function number_of_days($day, $start, $end)
{
    $w = array(date('w', $start), date('w', $end));

    return floor( ( $end - $start ) / ONE_WEEK ) + ( $w[0] > $w[1] ? $w[0] <= $day || $day <= $w[1] : $w[0] <= $day && $day <= $w[1] );
}

//$start = $end = time();

echo number_of_days(0, $start, $end); // SUNDAY
echo number_of_days(1, $start, $end); // MONDAY
echo number_of_days(2, $start, $end); // TUESDAY
echo number_of_days(3, $start, $end); // WEDNESDAY
echo number_of_days(4, $start, $end); // THURSDAY
echo number_of_days(5, $start, $end); // FRIDAY
echo number_of_days(6, $start, $end); // SATURDAY
?>
Alfred
  • 21,058
  • 61
  • 167
  • 249