Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Carbon returning the wrong date bug

I am manipulating my dates using the php Carbon package within my Laravel app. I am having some weird results when trying to generate a date (x days in the future)

Please take a look at this code:

$start_date = Carbon::tomorrow('Europe/London');
$end_date = $start_date->addDays($tier->duration_days);
Log::debug('Carbon::now(): '.Carbon::now());
Log::debug('Carbon::tomorrow(Europe/London): '.Carbon::tomorrow('Europe/London'));
Log::debug('$start_date: '.$start_date);
Log::debug('$end_date: '.$end_date);

The code above will print out the following debug lines:

2017-04-17 21:46:31] local.DEBUG: Carbon::now(): 2017-04-17 21:46:31
[2017-04-17 21:46:31] local.DEBUG: Carbon::tomorrow(Europe/London): 2017-04-18 00:00:00 [2017-04-17 21:46:31] local.DEBUG: $start_date: 2017-05-16 00:00:00 [2017-04-17 21:46:31] local.DEBUG: $end_date: 2017-05-16 00:00:00

Using Carbon::tomorrow() will print out the correct dates, however using $start_time which technically uses the same function returns the wrong date. Can someone advise what could be going wrong here?

FYI I have set Europe/London as my timezone in my config/app.php file.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

$date->addDays doesn't actually return an instance with the days added, it returns the same instance after modifying the days (which makes a great deal of difference).

Therefore, you should first copy the date into a new instance and then add the days.

$start_date->copy()->addDays($tier->duration_days);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!