Search code examples
datetimeformatphp-carbon

how to transform Carbon date into m-d-y format? (opposite)


I've this date format: November 12, 2018 and I want to transform it into (m-d-y) format to be able to insert it into DB (as dynamic data..). Any help will be appreciated.

checked most of the answers, all are talking how to convert from (d-m-y) into Carbon (human format) .. I couldn't find something for this.


Solution

  • Using 'Carbon', this will return the desired date format which is: 2021-12-27

    Carbon::parse('December 27, 2021')->format('Y-m-d');
    

    note: I'm using Laravel framework.