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 8870779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:49:21+00:00 2026-06-14T17:49:21+00:00

I used DateTime to get the diff of two dates. Directly from the PHP

  • 0

I used DateTime to get the diff of two dates. Directly from the PHP documentation example:

$date1 = new DateTime('2012/03/15');
$date2 = new DateTime('2012/6/9');
$interval = $date1->diff($date2,true);
$days = $interval->format('%R%a days');

This will result in +86 days, I wonder where can I get the reference for those %R%a I don’t know what they mean, but I just know by seeing that %R = + while %a is number of days.

Second, now by having the value 86 I can have at least a variable that I can use to tell that $date1 and $date2 is not within the length of 3 months (3 months is at least 90 days). I can simply use an if-else for this, however for precision, is there another way (built-in PHP functions or library) to determine that the value I have is within the period of 3 months?

  • 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-14T17:49:22+00:00Added an answer on June 14, 2026 at 5:49 pm
    1. Check the documentation for DateTime::diff.
    2. See that it returns a DateInterval, click link to its documentation.
    3. Read documentation for its format method.

    Use if ($interval->format('%m') > 3) to test if it’s over three months. Notice that this is only the months portion of the interval, e.g. “3” of “2 years, 3 months”. Take the years into account as well. You should not just use days for this, since there’s no constant number of days in a month. 90 days and 3 months are not the same thing.

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

Sidebar

Related Questions

I tried using DateTime in PHP and used diff method to find the time
I use the code below to get records from two tables but I want
Up until now I used DateTime.Now for getting timestamps, but I noticed that if
I'm using the following functions: # The epoch used in the datetime API. EPOCH
In my model i have propery: public DateTime CreatedFrom { get; set; } In
I have the following Nant Script snippet. <zip zipfile=${devEnvironment}..\dev-${datetime::get-year(datetime::now())}${datetime::get-month(datetime::now())}${datetime::get-day(datetime::now())}.zip> <fileset basedir=${devEnvironment}> <include name=**/*/> </fileset>
Is there any way in .Net I can get the default format used by
Taking the Stack Overflow tagging system as the canonical example, how can I get
Let's say in my model I have public DateTime Date {get;set;} property. On the
I have a model with a DateTime propery: [DisplayName(Updated)] public DateTime lastUpdatedDate { get;

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.