Php - Date

> Procedural Languages > Php

1 - Management

1.1 - Get current date

See date

$dateIso8601 = date('c');
Advertising

1.2 - String to Date

1.2.1 - To DateTime

$dateInputFormat = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($dateInputFormat, "2017-09-18 12:20:22");

1.2.2 - To Timestamp

$dateInputFormat = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($dateInputFormat, "2017-09-18 12:20:22");
$date->getTimestamp();

1.3 - Date to String

1.3.1 - From a timestamp

string date ( string $format [, int $timestamp = time() ] )

Example

date('l jS \of F Y h:i:s A',1391624456)
Wednesday 5th of February 2014 07:20:56 PM

1.3.2 - From a datetime

$datetime->format('Y-m-d'); 

2 - Documentation / Reference

Advertising