Skip to content

Instantly share code, notes, and snippets.

@llagerlof
Created August 12, 2019 19:00
Show Gist options
  • Select an option

  • Save llagerlof/5ad52f410a7342a6584148bbfb97d053 to your computer and use it in GitHub Desktop.

Select an option

Save llagerlof/5ad52f410a7342a6584148bbfb97d053 to your computer and use it in GitHub Desktop.
One liner to identify a valid datetime "Y-m-d H:i:s" on PHP
<?php
/*
This script can be used on terminal. Eg:
$ php id_date_valid.php 2019-08-12 15:23:58
*/
$datetime = $argv[1] . ' ' . $argv[2];
if ($datetime == date('Y-m-d H:i:s', strtotime ($datetime))) {
echo "true";
} else {
echo "false";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment