php get day of the week code example

Example 1: get day from date php

// Prints the day
echo date("l") . "<br>";

Example 2: date in php

/**
 * Its always best to use a datetime object
 */
$dateTime = new \DateTime();
/**
 * You can get the string by using format
 */
$dateTime->format('Y-m-d H:i:s');

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: name of today php

$datetime = DateTime::createFromFormat('YmdHi', '201308131830');
echo $datetime->format('D');

// or 

$date = new \DateTime();
echo $date->format("D");

Example 5: show date php by letters

check here link:   http://www.eltcalendar.com/stuff/datemysqlphp.html

Tags:

Php Example