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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:30:41+00:00 2026-06-13T02:30:41+00:00

I have a database table with column DATETIME called ‘entry_date’, such as… ID entry_date

  • 0

I have a database table with column DATETIME called ‘entry_date’, such as…

ID  entry_date
1   2012-10-13
2   2012-10-14
3   2012-10-15
4   2012-10-20
5   2012-10-20
6   2012-10-21

Whats the best way of echoing out the result for based on DATE in PHP/MYSQL, so i get just the results for this week so 2012-10-15 > 2012-10-21, but obviously i can’t just code that out because days change, everyday 🙂 so how would you do that in php so tomorrow the condition for this week would be 2012-10-16 > 2012-10-22

  • 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-13T02:30:42+00:00Added an answer on June 13, 2026 at 2:30 am

    For today, use

    where date(`entry_date`) = curdate()
    

    For this month,

    where month(`entry_date`) = month(curdate()) 
    and  year(`entry_date`) = year(curdate()) 
    

    For this week

    WHERE `entry_date` 
    BETWEEN (CURDATE() - Interval DAYOFWEEK(CURDATE()) day) 
    AND (CURDATE() - Interval DAYOFWEEK(CURDATE()) day + Interval 1 week)
    

    Above query is good for understanding. But not good for performance point of view. See the bellow modified one. Its far better.

    SET @s:=(CURDATE() - Interval DAYOFWEEK(CURDATE()) day)
    SET @e:=(CURDATE() - Interval DAYOFWEEK(CURDATE()) day + Interval 1 week)
    SELECT ....  WHERE `entry_date` BETWEEN @s AND @e
    

    Here DAYOFWEEK function returns an integer number starting from 1=Sunday. So your weeks will be counted as Saturday as starting date. If you want Monday add + Interval 2 day with Interval.

    It can be also simplified to the following. But it does not support any day as first day of week. So its not portable to all culture.

    where yearweek(`entry_date`) = yearweek(curdate())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with a column called 'symbol', that is unique via
In database table I have column called options . It has type of integer
I use PostgreSQL database and in one table I have the datetime column edit_user
I have a database table with a datetime column. Everything works fine if a
In MySql database have AM_TIMETABLE table in that UserId DateTime 101 2012-08-08 04:00:00 102
I have a datetime column in a table called 'createdDate' were the default value
I have a mysql database table that gets the datetime column automatically filled when
I have a table which has a DATETIME column called dtInsertDate . The value
I have a textbox which is binded to a specific database table column. This
I have a database table named 'student' in which there is one column named

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.