day of week php code example

Example 1: php get day from date

$timestamp = strtotime('2009-10-22');

$day = date('D', $timestamp);
var_dump($day);

Example 2: php check weekday of date

$dayofweek = date('w', strtotime($date));
$result    = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));

Example 3: 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 4: php date

$dateTime = new \DateTime();
/**
 * You can get the string by using format
 */
$dateTime->format('Y-m-d H:i:s');