php get week start and end date code example

Example 1: php get day of week

date('w'); //gets day of week as number(0=sunday,1=monday...,6=sat)

//note:returns 0 through 6 but as string so to check if monday do this:
if(date('w') == 1){
	echo "its monday baby";
}

Example 2: week starting date and end date in php

<?php$week=29;$year=2017;function getStartAndEndDate($week, $year) {  $dateTime = new DateTime();  $dateTime->setISODate($year, $week);  $result['start_date'] = $dateTime->format('d-M-Y');  $dateTime->modify('+6 days');  $result['end_date'] = $dateTime->format('d-M-Y');  return $result;}$dates=getStartAndEndDate($week,$year);print_r($dates);?>

Tags:

Php Example