80257

How can I add date with another date in carbon laravel?

In my laravel project, I want to increase the date time with the previous date time.

Here is my code

$expire=$order[0]->expire_date; $new=Carbon::now()->addMonths(6);

The results of these two lines are

2018-01-28 21:23:56 2018-06-28 21:43:29

What I want to do is sum the both dates.

$expire+$new

How can I achieve this? Any idea or thought? Thanks.

<strong>Edit with more clear view</strong>

I want to find the remaining days of the expire date from now and then want to add this remaining date with the new date. Hope it clears.

Answer1:

If you want to add six months to order expiration date, just do this:

$new = $order[0]->expire_date->addMonths(6);

This will work since $order[0]->expire_date is a Carbon instance.

If it's not, just parse it first:

$new = Carbon::parse($order[0]->expire_date)->addMonths(6);

Answer2:

you can add something like that:

$new=Carbon::createFromTimestamp($order[0]->expire_date->timestamp)->addMonths(6);

Recommend

  • Solr Multivalued date range from two separate field as sub entity
  • Create folder in root directiry of and upload file to that folder google drive api
  • How can i use jQuery datepicker in dynamically
  • PHP Carbon DateTime adds two months and skips november entirely
  • Forms Authentication cookie seems to stop working
  • Login and Logout in master page
  • How to set a default value to a DateTime parameter
  • Change “carbon.super Profile Service” to custom name
  • Finder Plugin in Snow Leopard
  • How to execute “sudo nvm”?
  • WSO2 as a Service Provider
  • Handsontable increase row header width
  • Is there a greater chance to collide when comparing GUIDs based on a hash vs \"Guid.NewGuid()?
  • detecting end of http header with \\r\\n\\r\\n
  • MS SQL Server 2008 :Getting start date and end date of the week to next 8 weeks
  • Using Python objects in C++
  • TCPDF's getNumLines() is sometimes wrong
  • Aggregating two data frame columns without any existing pattern logic
  • data.table replicate rows after join?
  • calculating number of bytes of each row in an image
  • Write output of for loop to multiple files
  • Plotting densities in R
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Approximate Order-Preserving Huffman Code
  • Django model inheritance, filtering models
  • Grails calculated field in SQL
  • Magento Fatal error: Maximum execution error solution, on WAMP
  • Insert into database using onclick function
  • Read text file and split every line in MSBuild
  • Is possible to count alias result on mysql
  • Knitr HTML Loop - Some HTML output, some R output
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Return words with double consecutive letters
  • how to add data labels for bar graph in matlab
  • Benchmarking RAM performance - UWP and C#
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?