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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:14:08+00:00 2026-05-17T15:14:08+00:00

I want to get the absolute days away a datetime is from today. For

  • 0

I want to get the absolute days away a datetime is from today. For example, i would like to know if a date is 2 days away, or 78 days away, or even 5,239 days away (not likely, but you get the idea). I am using an MS SQL database which is returning datetimes where the time components are all 00:00:00.

date_diff returns relative values that you then have to do some crazy math with to get absolute dates do to calculating months, years, etc.

Also, i am having issues getting the date component only of today’s date in php.

Edit:
Thanks to mr. w. This is what i ended up with:

    $date = $row['AirdateDateTime'];
    $today = date_create(date("Y-m-d"));
    $away = date_diff($today, $date);
    $d = $away->format("%R%a");

The date_create() part was the part i was originally missing to convert to an actual datetime. Also, the format needs to be %R%a. Using %R%d only works for dates in this month.

  • 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-05-17T15:14:09+00:00Added an answer on May 17, 2026 at 3:14 pm

    The date_diff() function (really, the DateTime::diff() method) is what you want, and it’s actually not hard. In fact, I think the example in the docs is exactly what you’re after:

    <?php
        $datetime1 = new DateTime('2009-10-11');
        $datetime2 = new DateTime('2009-10-13');
        $interval = $datetime1->diff($datetime2);
        echo $interval->format('%R%d days');
    ?>
    

    or

    <?php
        $datetime1 = date_create('2009-10-11');
        $datetime2 = date_create('2009-10-13');
        $interval = date_diff($datetime1, $datetime2);
        echo $interval->format('%R%d days');
    ?>
    

    What’s returned is a DateInterval object, which you can format any way you want with its format() method. Above, it’s being formatted to days, but you have a ton of options; see http://us.php.net/manual/en/dateinterval.format.php.

    You shouldn’t need to do any math yourself.

    [EDIT – forgot this part]

    As for getting the date component of today’s date, you can do something like this:

    <?php
        echo date('Y-m-d');
    ?>
    

    See http://us.php.net/manual/en/function.date.php.

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

Sidebar

Related Questions

I want to get 100 and example from this string ?connect:100/username:example/ I searched in
I want to get the relative URL from an absolute URL in JavaScript using
I have a VB console application. I would like to get the absolute URL
I want get as much as possible from Redis + Hiredis + libevent. I'm
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I want to get the absolute value of a number in JavaScript. That is,
In my FF extension, I want to get the absolute URL of all the
I want to get an object's absolute x,y position on the page in Javascript.
Hi this is an example of my code. I want to get the margin-top

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.