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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:34:07+00:00 2026-06-11T07:34:07+00:00

I have a date that returns in a string as 2012-03-19 05:00:32, its not

  • 0

I have a date that returns in a string as 2012-03-19 05:00:32, its not coming from the database

I can use below to search for the last 30 days

$date = '2012-03-19 05:00:32';
if (strtotime($date) >= strtotime('-7 days')) {
// do something
}

Problem is if today is the 19th March, i was to search from the 11th to the 18th for the last 7 days and that seems to search for the last 7 days by calculating 24 hours * 7 by my searches need to start from 00:00:01 each day.

My plan is to break the date down into Year, Month and Day then check if year = 12, then check if month = 3, then check if date between 11 and 18.

Im just wondering if there is a more efficient way to do this or if im on the right track.

I also have the same issue with running a search on all info from this month and also want to search for all info this week starting on Monday.

So this is just asking if my method is sound or if there is a more efficient method.

  • 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-11T07:34:09+00:00Added an answer on June 11, 2026 at 7:34 am
    $mytime = new DateTime('2012-03-19 05:00:32');
    $mydate = new DateTime($mytime->format('Y-m-d')); //keep date only, exclude the time component
    $now=new DateTime; //includes hours, minutes, seconds
    $today=new DateTime($now->format('Y-m-d')); //time set to 0:00
    
    $interval = $mydate->diff($today);
    if($interval->format('d') <=7) { //assuming that $mydate isn't in the past
     //do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database script that returns date time string and my problem is
I have a case statement that returns a date; case when (ma.first_active_date is not
I have a function that returns a date from a stored procedure, and it
I have a function that returns me a date string using Zend_Date . $date
I have to validate the format of a date string coming from a csv
I have a stored procedure that returns data in the format of: Date |
Let's say I have a date that I can represent in a culture-invariant format
I'm using .NET 3.5 and I have a date that comes in as string
I currently have the following funciton in an oracle database that returns a concatenated
I have a column which is a string, it holds values like that: 11.05.2012

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.