Php - Time (Date)

Card Puncher Data Processing

Management

Get current date

See date

$dateIso8601 = date('c');
time()

Timestamp

Unix timestamp (in second) One hour ago

$time = time() - 3600;

Add

Add a day

$date = new DateTime();
$date->modify('+1 day');

Add seconds

$expirationTime = new DateTime();
$expirationTime->modify('+'.$cacheIntervalInSecond.' seconds')

String to Date

To DateTime

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

To Timestamp

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

Date to String

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

From a datetime

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

Diff

Get time difference in number of days

$diff = $sourceModifiedTime->diff($compiledModifiedTime);
$daysBetween = $diff->format('%a');
$secondsBetween = $diff->format('%s');
round((time() - $timestampCreation)/60/60/24)

Greater than

For Datetime

$dateTime1 > $dateTime2

Documentation / Reference





Discover More
Card Puncher Data Processing
PHP - Data Type

data type in PHP When a variable is unknown to an IDE (phpStorm), by adding a phpdoc comments describing it, allows PhpStorm to discover type information and provide with a complete accurate...



Share this page:
Follow us:
Task Runner