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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:55:45+00:00 2026-05-23T05:55:45+00:00

I am writing a script to query dates 3 months ago. As I am

  • 0

I am writing a script to query dates “3 months ago”. As I am thinking about making sure I do not miss anything, I am using this for comparison:

$date = date("Y-m-d",mktime(0,0,0,date("m")-$months_ago,date("d")));

I am realizing there is a chance I could be missing dates. For example, if I search on 11/30 for dates three months ago, I will get 8/30. But the next day is 12/1 and three months prior is 9/1. So in this script I have missed 8/31.

I guess the best method is to use days (90 days) instead on months. Is this the best practice for something like this?

  • 1 1 Answer
  • 1 View
  • 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-23T05:55:46+00:00Added an answer on May 23, 2026 at 5:55 am

    Go directly with strtotime('-3 month'); you can also give negatives like -3 on the month param of the mktime and it will work like charm (better the second solution). No, it wont skip days – if “now” is 2011-06-17 it would return timestamp equivalent to 2011-03-17.

    Edit:
    Well, it might actually be true that you can miss days (I haven’t checked your statement) but after all your unit of measurement of time is months, not days. What I’m saying is that in the Gregorian calendar month isn’t constant amount of time – it could be 28, 29, 30 or 31 days.

    Let’s say you want to calculate months for a paid subscription period. If the user pays one month on 2011-02-15, when would his subscription expire? I would guess 2011-03-15, even though there are just 28 days between those two dates And if he pays for subscription on 2011-03-15, he would get full 31 days till 2011-04-15 and this seems perfectly fair to me as the subscription is “one month”, which just happens to be different amount of days through the year.

    If, in your case you don’t want to get “3 months ago” but want to get constant amount of time that relatively represents “3 months”, then you can use the medium month length – 88.59 days, or 88 days 14 hours and 10 minutes. That represented with code would be:

    strtotime('-88 days -14 hours -10 minutes');

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

Sidebar

Related Questions

I'm writing a python CGI script that will query a MySQL database. I'm using
I am writing a script using DBI to execute a select query to an
I'm writing a PHP script that builds an SQL query by concatenating the string
I am writing a script that checks if given domain is parked or not.
I just finished writing this script and getting it to work but I need
I'm writing a script (mostly for learning purposes) for logging into a database, using
I am currently writing a script whereby an array of checkboxes are displayed using:
I am writing a script to access a specific detail about the user and
I am writing a VBScript script to execute an SQL query in the SQLite
currently I'm making a forum software, and I'm writing the install script, that sets

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.