Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda