php-carbon

How to convert date format from dd/mm/yyyy to yyyy-mm-dd using carbon on Laravel

牧云@^-^@ 提交于 2019-12-11 13:43:01
问题 I have small laravel project working on date conversion. I have date string that getting from request on format dd/mm/yyyy. Code and result show as below. $request->stockupdate ; // dd/mm/yyyy (02/05/2019) Then I try to convert to yyyy-mm-dd using carbon. $_stockupdate= Carbon::parse($request->stockupdate)->format('Y-m-d'); I got parse result as below. 2019/02/05 // Seem it is 2 Feb 2019 not 5 May 2019. That's wrong, It should be 2019/05/02 instead. Any advise or guidance would be greatly

Display all dates on models in the user’s timezone (Laravel)

懵懂的女人 提交于 2019-12-11 10:32:43
问题 I have the users timezone stored (there is timezone column in the users DB table) and I want to display all $dates attributes on all models in the user’s timezone, if authenticated . I'm trying to find an elegant way to do this... Ideally, when there is something like this in Blade views: {{ $post->created_at }} OR {{ $post->created_at->format('h:i:s A') }} ... for authenticated users it would be automatically in their timezones. How would you handle this? I'm thinking about creating one

Carbon get years between specified start year and current year

佐手、 提交于 2019-12-11 06:23:42
问题 Is there anyway to get the years between a start year and current year in an array, if possible with Carbon? So this year the array would be: [2014,2015,2016] And next year 2017 will be included: [2014,2015,2016,2017] Thanks.. 回答1: Solution: $years = range(Carbon::now()->year, 2014) 来源: https://stackoverflow.com/questions/40007075/carbon-get-years-between-specified-start-year-and-current-year

Carbon::now() with time-offset result in different behaviors

浪尽此生 提交于 2019-12-11 01:38:01
问题 I'am using Carbon for manipulating dates in a laravel project. Carbon::now('+5:30'); Above code is working fine in local environment but not in development environment. This is what i get on dd(Carbon::now('+5:30')); 1 - IN LOCAL ENVIRONMENT php version - 5.6.3 2 - IN DEVELOPMENT ENVIRONMENT php version - 5.5.9-1ubuntu4.14 But both environment behaves same if i use timezone name instead of time-offset like, Carbon::now('Asia/Tokyo'); Is this something about the php-version or something else?

Carbon locale format and decline

Deadly 提交于 2019-12-11 01:12:32
问题 How I can set locale to carbon with format? I have date: setlocale(LC_TIME, 'ru_RU.UTF-8'); Carbon::setLocale('ru'); $dt = Carbon::now()->formatLocalized('%d %M'); I Get Month with: 25 декабрь How I can get locale with decline? Example: 25 декабря 回答1: I've just tested it and this will return 25 декабря : Carbon::now()->formatLocalized('%d %B'); In comments, you've said you have trouble with the date. Try this fix, from the Carbon Docs: on Linux If you have trouble with translations, check

PHP Carbon DateTime adds two months and skips november entirely

◇◆丶佛笑我妖孽 提交于 2019-12-10 22:49:26
问题 I need to display three calendars one for the current month and the other two for the next two months. I am using Carbon to do these calculations. Today is the 31st of October. If I write the following $carbon = Carbon::now('UTC'); // current datetime in UTC is 8:54 AM October 31, 2016 echo $carbon->format('F') . '<br>'; echo $carbon->addMonths(1)->format('F'); I get this output October December I am completely missing November... so how do I add a month on to October so that I get November.

How to add CarbonInterval instance in Carbon instance

雨燕双飞 提交于 2019-12-10 21:06:42
问题 I have a carbon instance $a = Carbon\Carbon::now(); Carbon\Carbon { "date": "2018-06-11 10:00:00", "timezone_type": 3, "timezone": "Europe/Vienna", } and a CarbonInterval instance $b = CarbonInterval::make('1month'); Carbon\CarbonInterval { "y": 0, "m": 1, "d": 0, "h": 0, "i": 0, "s": 0, "f": 0.0, "weekday": 0, "weekday_behavior": 0, "first_last_day_of": 0, "invert": 0, "days": false, "special_type": 0, "special_amount": 0, "have_weekday_relative": 0, "have_special_relative": 0, } How to add

Carbon - why addMonths() change the day of month?

浪子不回头ぞ 提交于 2019-12-10 12:57:53
问题 Here's the simple example (today is 2016-08-29): var_dump(Carbon::now()); var_dump(Carbon::now()->addMonths(6)); Output: object(Carbon\Carbon)#303 (3) { ["date"] => string(26) "2016-08-29 15:37:11.000000" } object(Carbon\Carbon)#303 (3) { ["date"] => string(26) "2017-03-01 15:37:11.000000" } For Carbon::now()->addMonths(6) I'm expecting 2017-02-29 , not 2017-03-01 . Am I missing something about date modifications? 回答1: There is no 2/29/2017. Leap-year happened in 2016. The following link:

Carbon.php The separation symbol could not be found Data missing

帅比萌擦擦* 提交于 2019-12-08 16:37:27
问题 First, I retrieve all the records, //get inventory items $inv = inventory::all(); and then I loop on the retrieved records and modify the created_at and updated_at data to make it more human readable date. foreach($inv as $i){ $i->created_at = date("M d, Y",strtotime($i->created_at)); $i->updated_at = date("M d, Y",strtotime($i->updated_at)); } but it returns me this error, InvalidArgumentException in Carbon.php line 425: Unexpected data found. Unexpected data found. The separation symbol

Incrementing dates with Carbon

空扰寡人 提交于 2019-12-08 14:57:56
问题 I'm trying to create an array of blackout dates for a reservation system in Laravel 4. There is one test row in my db with a start_date of 2016-01-24 and end_date of 2016-01-29. This is the code that pulls the row and loops through the dates using Carbon to increment by one day & add it to an array: $reserved = Reservation::where('property_id', $property->id)->get(); $blackoutDays = []; foreach($reserved as $r) { $start = new \Carbon\Carbon($r->start_date); $end = new \Carbon\Carbon($r->end