php date month name code example

Example 1: php get day from date

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

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

Example 2: datetime get month php

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

Example 3: 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 4: get month from database php

echo 'Day' . date('d', strtotime($row['Date']));
echo 'Month' . date('m', strtotime($row['Date']));
echo 'Year' . date('Y', strtotime($row['Date']));

Example 5: date format with t and z php

str_replace('+00:00', '.000Z', gmdate('c', strtotime('2013-05-07 18:56:57')))

Example 6: php date

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

Tags:

Php Example