input :17-07-2017
output->> 3rd Monday
Thanks in advance
Here is my code:
$datee = "2017-07-17";
$timestamp = strtotime($datee);
$day = date('l', $timestamp);
$week = date('w', $timestamp);
echo $day;
echo $week;
input :17-07-2017
output->> 3rd Monday
Thanks in advance
Here is my code:
$datee = "2017-07-17";
$timestamp = strtotime($datee);
$day = date('l', $timestamp);
$week = date('w', $timestamp);
echo $day;
echo $week;
$input = new \DateTime('2017-07-17');
$firstDayOfMonth = new \DateTime($input->format('Y-m-01'));
$order = (int)(($input->format('j') - 1) / 7) + 1;
function ordinal($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if ((($number % 100) >= 11) && (($number%100) <= 13))
return $number. 'th';
else
return $number. $ends[$number % 10];
}
echo ordinal($order).' '.$input->format('l');
You can tinker with the code at https://3v4l.org/dg5Xa
Very simple answer is already there
In PHP, how to know how many mondays have passed in this month uptil today?
$now=time();
if (($dow = date('w', $now)) == 0) $dow = 7;
$begin = $now - (86400 * ($dow-1));
echo "Monday: ".ceil(date('d', $begin) / 7)."<br/>";
'w' format is a numeric representation of the day (0 for Sunday, 6 for Saturday). It doesn't represent week of the month. To get the week of the month you can use the following function
function week_number( $date = 'today' ) {
return ceil( date( 'j', strtotime( $date ) ) / 7 );
}
So your code should be:
$datee = "2017-07-17";
$timestamp = strtotime($datee);
$day = date('l', $timestamp);
$week = week_number($datee);
echo $day;
echo $week;
Reference: Get week number in month from date in PHP?