Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Multiple Formats with PHP DateTime::createFromFormat()

$date = '20200727';
$formats = ['Y-m-d', 'Y/m/d', 'Ymd'];
$dateObj = null;
foreach ($formats as $format) {
    try{
        if ($dateObj = Carbon::createFromFormat($format, $date)){
            break;   
        }
    } catch (InvalidArgumentException $e) {
        Log::debug('date', [$dateObj]); // It's null
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel model relationships with two columns match 
Php :: Target class [LoginController] does not exist. 
Php :: ultimo numeto php 
Php :: create new laravel project 
Php :: nodejs php 
Php :: php order array by specific key 
Php :: laravel validate string 
Php :: php get result sql server 
Php :: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.29 Server at localhost Port 8080 
Php :: php get current date 
Php :: undefined reference to 
Php :: Target class [AppHttpControllersAdminUserController] does not exist. larvel 8 
Php :: store a variable in session and echo that variable on a page wordpress 
Php :: image::make en php 
Php :: Attempt to read property "name" on bool 
Php :: progress bar calculate percentage php 
Php :: insert chevron on form select field on caldera 
Java :: basic hello world program in java 
Java :: how to set current date in android studio 
Java :: import android.support.v4.app.ActivityCompat; 
Java :: javafx button color 
Java :: open link in android studio 
Java :: java check if able to parse int 
Java :: allow internet permission android 
Java :: How to turn off darkmode for my app in android studio 
Java :: How can I put a parameter into a localized string in Android? 
Java :: java bufferedimage get int array 
Java :: jframe add label java 
Java :: android studio visibility 
Java :: find difference in days between two dates java 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =