0

I've put together some code in order to get the current date and find Monday's date from it. Problem is, it finds the next Monday, not the current/past Monday. How would I be able to revise my code to show this? Also, I'm still new to CodeIgniter and learning; separate question, is my code okay for CodeIgniter? Or, is there also a better way of writing it out without mktime? Thanks in advance!

See below for code:

// get current week and convert it to a week number
        $ddate = date('Y-m-d');
        $date = new DateTime($ddate);

        $week = $date->format("W");
        $year = date('Y');

        $timestamp = mktime( 0, 0, 0, 1, 1,  $year ) + ( $week * 7 * 24 * 60 * 60 );
        $timestampForMonday = $timestamp - 86400 * ( date( 'N', $timestamp ) - 1 );
        $dateForMonday = date( 'M-d-Y', $timestampForMonday );

        // echo $dateForMonday;
        $data['dateForMonday'] = $dateForMonday;
dharrison
  • 3
  • 2
  • what do you mean by "get the current date and find Monday's date from it"? Which Monday do you wish to find, past Monday, current Monday or next Monday or all past Mondays or all Mondays? – sauhardnc May 13 '20 at 11:26
  • The date for Monday of the current week. This week's Monday would be 5-11-20, however my code generates 5-18-20 instead. – dharrison May 13 '20 at 11:33

0 Answers0