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;