Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7712559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:39:45+00:00 2026-06-01T01:39:45+00:00

i am using the following code(based on this http://goo.gl/5HhSx ) to calculate the difference

  • 0

i am using the following code(based on this http://goo.gl/5HhSx) to calculate the difference between dates:

<?php
$date1 = '2012-03-29';
$date2 = '2012-04-02';
$datetime1 = date_create($date1);
$datetime2 = date_create($date2);
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%a days');
?>

The difference is 4 days.March has a fixed price(30€/day) and April has another(40€/day).
Is there a way to sum the whole price? Three days until the end of march and another two from april? How can i add them correctly?
Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:39:46+00:00Added an answer on June 1, 2026 at 1:39 am

    For your exact example this works:

    $date1 = '2012-03-29';
    $dateBoundary = substr($date1, 0, 8).date('t', strtotime($date1));
    $date2 = '2012-04-02';
    $marchPrice = 30;
    $aprilPrice = 40;
    $datetime1 = date_create($date1);
    $datetime1Boundary = date_create($dateBoundary);
    $datetime2 = date_create($date2);
    $interval1 = date_diff($datetime1, $datetime1Boundary);
    $interval2 = date_diff($datetime1Boundary, $datetime2);
    $totalPrice = ($interval1->format('%d') * $marchPrice) + ($interval2->format('%d') * $aprilPrice);
    echo number_format($totalPrice, 2);
    

    You can of course extrapolate the idea for periods which span multiple months.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/
I'm using the following code to cause a ul based dropdown menu to open,
I'm using following code but cannot return data from MySQL. This is the output:
I am using the following code to load my flash file, contact a php
I'm using this tutorial as the basis for a Code Igniter / Doctrine based
I am making a tile game. Was following http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d . Using the whole screen
I have a question based on this question In the section http://www.parashift.com/c%2B%2B-faq-lite/private-inheritance.html#faq-24.3 the following
Based on this http://sourcemaking.com/design_patterns/command/cpp/1 , I think the posted code has memory leak b/c
Using the less-rails gem. Using the following code to mix two colours: @base: #ffdc52;
I have the following code: #include <iostream> #include boost/shared_ptr.hpp using boost::shared_ptr; class Base {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.