Created
June 13, 2016 09:54
-
-
Save phamngsinh/45f7439b6e8210fcb24746238af735f1 to your computer and use it in GitHub Desktop.
Laravel, PHP Validate Datetime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $time = null; | |
| if($timestamps instanceof DateTime){ | |
| $time = new \Carbon\Carbon($timestamps); | |
| } | |
| if($timestamps instanceof \Carbon\Carbon){ | |
| $time = $timestamps; | |
| } | |
| if (is_integer($timestamps) && strtotime(date($format, $timestamps)) === (int)$timestamps) { | |
| $dateTime = date($format, $timestamps); | |
| $time = new \Carbon\Carbon($dateTime); | |
| } | |
| if (is_string($timestamps) && strtotime($timestamps)) { | |
| $dateTime = date($format, strtotime($timestamps)); | |
| $time = new \Carbon\Carbon($dateTime); | |
| } | |
| return $time; |
Author
phamngsinh
commented
Jun 13, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment