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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:43:40+00:00 2026-05-31T04:43:40+00:00

I trying to find a script which will round down a date to the

  • 0

I trying to find a script which will round down a date to the nearest day and tell me how many days different’s between them. Want it to return like this:

0 = today
1 = yesterday
2 = 2days ago…
you get the idea

This is what ive got so far.

$delta = ((strtotime(date('d/m/y', time())) - strtotime(date('d/m/y', $time))))/86400;

But this returns like this:

0 = for today
30 = yesterday
61 = for the day before….

It driving me mad…..

  • 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-31T04:43:41+00:00Added an answer on May 31, 2026 at 4:43 am

    Try using the format date('Y-m-d', $dateStr) (notice the order of year, month, day), as this is the prefered format for PHP date operations and one of the ISO8601 notations.

    Also, there’s a problem in the code you posted. No need for this: date('d/m/y', $time), as $time I presume is a string. It actually throws a Notice. See working code below:

    $timeStr = '2012-03-06';
    
    $delta = abs((strtotime(date('Y-m-d', time())) - strtotime($timeStr)))/(60*60*24);
    
    echo $delta;
    

    Should output 1, as the current date is 2012-03-07.

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

Sidebar

Related Questions

I am trying to write T-sql script which will find open records for one
I am trying to find a way to write a script which will check
I'm trying to create a batch script that will delete all sub directories which
I am trying to find a solution which will check whether a file is
I am trying to write a script which will automate a copy/paste of employee
I am trying to write a script which will move files older than 1
I'm trying to write a bash script which will, given the name of a
I am trying to find a script that detects if a device places position:
I have searched left and right. And I am trying to find a script
I am trying to find how to reference branch start commit from script. I

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.