php-carbon

Carbon createFromFormat unexpected result

左心房为你撑大大i 提交于 2021-02-10 06:15:17
问题 ::createFromFormat() results in being one month ahead: var_dump($_GET['archive']); var_dump(Carbon::createFromFormat('m/Y', $_GET['archive'])); Result: string '11/2015' (length=7) object(Carbon\Carbon)[160] public 'date' => string '2015-12-01 10:38:41.000000' (length=26) public 'timezone_type' => int 3 public 'timezone' => string 'Europe/London' (length=13) 回答1: Seems that you just got unlucky because you were testing on the 31st of the month. However, this is (apparently) a documented

php carbon check if now is between two times (10pm-8am)

℡╲_俬逩灬. 提交于 2021-02-07 11:39:24
问题 $start = '22:00:00'; $end = '08:00:00'; $now = Carbon::now('UTC'); How can I check if the time of $now is within the timerange? 回答1: There are several ways to achieve that by using Carbon. One of the easiest ways is using createFromTimeString and between methods: $now = Carbon::now(); $start = Carbon::createFromTimeString('22:00'); $end = Carbon::createFromTimeString('08:00')->addDay(); if ($now->between($start, $end)) { // ¯\_(ツ)_/¯ } 回答2: $start = '22:00:00'; $end = '08:00:00'; $now =

InvalidArgumentException in Carbon::createFromDate()->age

流过昼夜 提交于 2021-01-29 02:41:52
问题 Hello i'm writing a custom validation for input data in my laravel project. I'm using Carbon::createFromDate()->age in order to get user age and check whether he's 16 or more. I reckon i'm not doing it properly because i get InvalidArgumentException with such errors: The separation symbol could not be found The separation symbol could not be found A two digit minute could not be found Unexpected data found. Trailing data $rok is a year(1996 eg.) $miesiac is a month and $dzien is a Day. Pesel

Laravel Carbon returns incorrect time

微笑、不失礼 提交于 2021-01-28 13:52:48
问题 I have an issue with my Laravel app that I'm developing, the returns time is incorrect, I did specify the timezone on both config/app.php and php.ini file, and I did clear the cache on Laravel using the following commands: php artisan cache:clear php artisan view:clear php artisan config:cache Also, I restarted my PHP service after changing the timezone in php.ini file. I'm using XAMPP as a server. Please note: the only correct time is by using pure php function! Anyone can help me in

Monthly recurring event on specific date and skip any month if have less no of days compare to user's selected date

有些话、适合烂在心里 提交于 2021-01-28 07:41:16
问题 I am creating a app where user can create monthly event (Just like Google/Outlook), so if user has selected 31st date of any month and next month have 30 days than all next dates are changing to 30th . Same goes with 30th , lets say user selected 30th of December than after Feb all next date is changing to 28th . so if in next month days are lesser than user's selected date its changing the date to that. Example : Start Date : 2020-10-31 End Date : 2021-11-30 $diffInMonths = $startDate-

Create date - Carbon in Laravel

穿精又带淫゛_ 提交于 2021-01-20 23:55:41
问题 I'm starting to read about Carbon and can't seem to figure out how to create a carbon date . In the docs is says you can; Carbon::createFromDate($year, $month, $day, $tz); Carbon::createFromTime($hour, $minute, $second, $tz); Carbon::create($year, $month, $day, $hour, $minute, $second, $tz); But what if I just recieve a date like 2016-01-23 ? Do I have to strip out each part and feed it to carbon before I can create a carbon date? or maybe I receive time like 11:53:20 ?? I'm dealing with

Laravel Query Builder: select TIMESTAMP as Carbon object

前提是你 提交于 2020-12-12 01:58:08
问题 Is it possible to select a timestamp column as a Carbon date object using the query builder? DateCreated in the snippet below: $entities = DB::table('translation_review as tr') ... ->select('tr.AuthorID', 't.LanguageID', 't.DateCreated' /* <--- this one! */) ->get(); Update 1 : I have solved this manually by iterating over the result set and changing the DateChanged property manually, but I am not satisfied with this solution. It feels inelegant. foreach ($entities as $entity) $entity-