I want to change default date format in Rails. Format should be y/m/d . I add following code into my environment.rb
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.
merge!(:default => '%Y/%m/%d')
But it didn't work. How can I change default format? I use rails 2.3.8 version
You need to convert your string into Date object. For that, use Date#strptime . You can use Date#strftime to convert the Date object into preferred format.
So, let's add these variables to config/app. return [ 'date_format' => 'm/d/Y', 'date_format_javascript' => 'MM/DD/YYYY', ]; And then, in Laravel, we can use this: Carbon::createFromFormat(config('app. date_format'), $value)->format('Y-m-d'); Carbon::parse($value)->format(config('app.
Add a file to config/initializers with the following code:
Date::DATE_FORMATS[:default]="%Y/%m/%d"
Time::DATE_FORMATS[:default]="%Y/%m/%d %H:%M"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With