PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 4, 2022

[FIXED] Add days to date in Laravel

 January 04, 2022     laravel, laravel-5, php     No comments   

Issue

I am beginner in Laravel. I use in my project Laravel 5.8.

I have this code:

$userPromotionDays = $user->premiumDate; // 2019.08.28
$daysToAdd = 5

How can I add $userPromotionDays to $daysToAdd (in Laravel/Carbon)?


Solution

You can create date with custom format and then add days to it using carbon.

$date = Carbon::createFromFormat('Y.m.d', $user->premiumDate);
$daysToAdd = 5;
$date = $date->addDays($daysToAdd);
dd($date);

You can see details documentation here.



Answered By - Rahul
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing