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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:44:20+00:00 2026-06-10T15:44:20+00:00

Banging my head against the wall today working with dates. I am looping through

  • 0

Banging my head against the wall today working with dates.
I am looping through a bunch of datetimes and comparing them to the current date to determine how far away they are.

So I am returning things like ‘tomorow @ 4pm’ , ‘yesterday at 3pm’, ‘today at 12pm’ , ‘3 days ago’, ‘in 3 days’ etc.

It all works fine until it gets to around today/tomorow/yesterday.

Date diff is returning silly things like -0 and +0 when it gets to these dates.
My theory is that dates that are lets say… 23 hours in the future, or even 10 hours in the future, even if they take place on the ‘next day’ are returning as 0 instead of 1.

Unfortunately date_diff doesn’t appear to return decimals or allow me to do any sort of rounding.

Here is some sample code:

$difference = $meeting_date->diff($current_date);
$difference = $difference->format('%R%a');

I then check this difference integer to see if it is 0, -1, 1, < -1, or > 1.
I handle the preceding + sign where necessary.

The ones that are supposed to be -1 or +1, are sometimes returning as -0 or +0 (..what?)

Also, -0 is not = 0, but is apparently less then -1 according to PHP.

S.O.S, someone help.

I have read all the related questions, this is not a duplicate and it is not related to that random 6015 error. Also using diff->days is not the answer. This always returns an absolute and not negatives which would be a problem.

  • 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-10T15:44:22+00:00Added an answer on June 10, 2026 at 3:44 pm

    Hm… My approach here would be to split the time and date display. Something like this:


    $meeting_day = DateTime::createFromFormat($meeting_date->format('Y-m-d'));

    // set $today to today's date at 0:00

    $diff = $meeting_day->diff($today);

    That should give you a useable day-based difference (for rendering today, yesterday, tomorrow etc.).

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

Sidebar

Related Questions

I've been banging my head against a wall on this one. I'm working on
I am banging my head against the brick wall today. I am porting a
I have been banging my head against the wall- can anyone help with working
banging my head against the wall for something seemingly dead simple. Here it is:
I've been banging my head against a wall with this one for a couple
I've been banging my head against the wall all night trying to figure out
I've been banging my head against the wall for awhile on this but here
I have been banging my head against the wall with this odd behaviour on
I've been banging my head against the wall for a couple of days on
I'm literally banging my head against a wall here (as in, yes, physically, at

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.