php-carbon

Laravel Carbon localization not working (get localized name of month from number)

流过昼夜 提交于 2019-12-07 07:04:55
问题 Using Laravel 5.3, In my method I use setlocale(LC_TIME, 'hr-HR'); dd(Carbon::now()->formatLocalized('%A')); but I get Sunday instead of CroatianWordForSunday . I tried using Carbon::setLocale('hr') instead setlocale() but I still get Sunday . In my config/app.php file I have set 'locale' => 'hr' . Thing to note is that Carbon's diffForHumans() method is successfully translated if I use Carbon::setLocale('hr') . In the end all I'm trying to do is convert number 8 to August but in Croatian. I

How could i create carbon object from given datetime structure?

女生的网名这么多〃 提交于 2019-12-06 19:28:41
问题 I use laravel, i need to create carbon object from the timestamp that i received. TimeStamp : ' yy-mm-dd HH:mm ' ex. ' 2016-12-20 10:26 ' Is this possible ? Or Any other solution ? 回答1: Use Carbon::parse('2016-12-20 10:26'); , it will return a Carbon object. 回答2: Based on carbon doc, you can convert date string to carbon object like: 1) Carbon::parse('1975-05-21 22:23:00.123456') 2) Carbon::create($year, $month, $day, $hour, $minute, $second, $tz); 回答3: You can use parse() : Carbon::parse(

Laravel search for records 7 days old only

柔情痞子 提交于 2019-12-06 13:53:16
i am trying to pull records that are 7 days old only , not older or earlier. But its not working, i'm using Carbon. ->where(DB::raw('date(AppDate)'), Carbon::now()->subDays(7)) I have a solution, but its not using Carbon. ->whereRaw('DATE(AppDate) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)') You can use whereDate for that : ->whereDate('created_at', Carbon::now()->subDays(7)) ->get(); In the documentation : The whereDate method may be used to compare a column's value against a date PS : Since Laravel 5.3 porosh09 To sum my last 7 days of records: $date = \Carbon\Carbon::today()->subDays(7);

Laravel Carbon localization not working (get localized name of month from number)

血红的双手。 提交于 2019-12-05 15:50:56
Using Laravel 5.3, In my method I use setlocale(LC_TIME, 'hr-HR'); dd(Carbon::now()->formatLocalized('%A')); but I get Sunday instead of CroatianWordForSunday . I tried using Carbon::setLocale('hr') instead setlocale() but I still get Sunday . In my config/app.php file I have set 'locale' => 'hr' . Thing to note is that Carbon's diffForHumans() method is successfully translated if I use Carbon::setLocale('hr') . In the end all I'm trying to do is convert number 8 to August but in Croatian. I could always just manually change January to Siječanj and so on but it would be nice if it could be

How to set Laravel Carbon timezone for timestamps?

夙愿已清 提交于 2019-12-05 01:28:38
I have a project which is primarily based in CET region. I set CET in config/app.php, but all pivot timestamps in the base are stored in UTC time? How can I set "global" timezone for timestamps? i made this test: <?php $timezone = date_default_timezone_get(); echo "The current server timezone is: " . $timezone; echo "<br />".date('m/d/Y h:i:s a', time()); $mytime = Carbon\Carbon::now(); echo "<br />".$mytime->toDateTimeString(); ?> and here's the result: The current server timezone is: CET 06/09/2016 12:06:04 pm 2016-06-09 11:06:04 tnx Y Carbon uses the default DateTime PHP object, so use the

How could i create carbon object from given datetime structure?

坚强是说给别人听的谎言 提交于 2019-12-05 00:52:32
I use laravel, i need to create carbon object from the timestamp that i received. TimeStamp : ' yy-mm-dd HH:mm ' ex. ' 2016-12-20 10:26 ' Is this possible ? Or Any other solution ? Use Carbon::parse('2016-12-20 10:26'); , it will return a Carbon object. Based on carbon doc , you can convert date string to carbon object like: 1) Carbon::parse('1975-05-21 22:23:00.123456') 2) Carbon::create($year, $month, $day, $hour, $minute, $second, $tz); You can use parse() : Carbon::parse($dateString); Or you can use $dates property to create Carbon instance automatically for the column: protected $dates =

timestampTz fields in Laravel

和自甴很熟 提交于 2019-12-04 20:56:17
Laravel 5.4 supports the Postgres TIMESTAMP WITH TIME ZONE field type in migrations: $table->timestampTz('scheduled_for'); Laravel can be set up to convert date fields ( DATE , DATETIME , TIMESTAMP ) into Carbon objects (and does so by default for the created_at and updated_at TIMESTAMP fields), but putting scheduled_for into the $dates field causes an error with the timezone-aware version: InvalidArgumentException with message 'Trailing data' Looking in the database and tinker, the field's value appears to be something like 2017-06-19 19:19:19-04 . Is there a native way to get a Carbon object

Can't catch Exception thrown by Carbon

可紊 提交于 2019-12-04 02:28:24
The following code throws an exception that I can't catch for whatever reason. try { $this->date = \Carbon\Carbon::parse($this->date)->toDateString(); } catch (Exception $err) { $this->date = \Carbon\Carbon::parse("January 1st 1900")->toDateString(); } Now, if I put this in my routes file in a function closure, it works fine. It's only throwing an exception when it's called from the Model. exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Summer 2015) at position 0 (S): The timezone could not be found in the database' in /home/vagrant/www/steamcompare

Format Timezone for Carbon Date

早过忘川 提交于 2019-12-03 09:43:51
I'm trying to set the timezone for a date in a Carbon object. It works fine locally but on my production box it keeps giving me Bad timezone error. I've tried: $date->setTimezone('7'); $date->setTimezone('+7'); $date->setTimezone('7:00'); $date->setTimezone('+7:00'); $date->setTimezone('UTC 7'); $date->setTimezone('UTC +7'); $date->setTimezone('UTC 7:00'); $date->setTimezone('UTC +7:00'); No idea why it's complaining on my production box. Can't find documentation either on what is the "proper" format to enter here. Can someone please help. FYI: local is windows, and prod is Ubuntu box. You can

Class Carbon\Carbon not found

大兔子大兔子 提交于 2019-12-03 07:01:28
问题 I recently added a package to my Laravel 4 site and now anything that uses Eloquent (or at least Eloquent with any reference to date/time) is showing a 500 error that states: Class 'Carbon\Carbon' Not Found. I tried running composer install composer update composer dump-autoload 回答1: Not saying this is work for you, but those are steps that usually fix Laravel, when the problem is not on your source code, of course: cd /your/application/dir rm bootstrap/compiled.php rm -rf vendor composer