php datetime get day code example

Example 1: php get day from date

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

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

Example 2: datetime php

$dateTime = new \DateTime();
$dateTime->format('Y-m-d H:i:s');

Example 3: datetime get month php

$dateTime = new DateTime();
$month = $dateTime->format('m');

Example 4: get day from date php

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

Example 5: date time format php

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm

Example 6: how to check the day of any date in php

// how to check the day of any date in php?

//Our YYYY-MM-DD date string.
$date = $request->start_date;

//Convert the date string into a unix timestamp.
$unixTimestamp = strtotime($date);

//Get the day of the week using PHP's date function.
$dayOfWeek = date("l", $unixTimestamp);

//Print out the day that our date fell on.
$day = $date . ' fell on a ' . $dayOfWeek;

Tags:

Php Example