Skip to content

Instantly share code, notes, and snippets.

@ederrafo
Last active August 9, 2022 04:27
Show Gist options
  • Save ederrafo/bcf32373863abe219ac8d05f2a345be3 to your computer and use it in GitHub Desktop.
Save ederrafo/bcf32373863abe219ac8d05f2a345be3 to your computer and use it in GitHub Desktop.
date php
<?php
$datetime = new \DateTime('2012-10-10');
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
/*Get number of day */
$numberDay = date('N');
// Get current time in timestamp
$time = time();
echo "<pre>",__FILE__." on line ".__LINE__,": "; print_r($time); echo "</pre>";
// print human readable
$print = date('H:i:s', $time);
echo "<pre>",__FILE__." on line ".__LINE__,": "; print_r($print); echo "</pre>";
// Convert hour, minute to timestamp
$hour = "07";
$minute = "00";
$second = "00";
$mktime = mktime($hour,$minute,$second);
echo "<pre>",__FILE__." on line ".__LINE__,": "; print_r($mktime); echo "</pre>";
// date parse
$now = new \DateTime(date('Y-m-d H:i:s'));
echo __FILE__." on line ".__LINE__,": "; print_r($now); echo "\n";
$timeLimit = '08/08/2022 23:25:00';
$timeLimit = \DateTime::createFromFormat('d/m/Y H:i:s', $timeLimit);
echo __FILE__." on line ".__LINE__,": "; print_r($timeLimit); echo "\n";
$interval = $now->diff($timeLimit);
echo __FILE__." on line ".__LINE__,": "; print_r( $interval->format('%i')); echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment