Solved

Date within mySQL query

Posted on 2011-09-16
5
317 Views
Last Modified: 2012-05-12
Is there a way to within a query to use a date calculation to do the following rather than having to do it with php

select * from table
where DATE >=  '2011-09-17' (todays date)
AND DATE <=  '2011-09-24'  (one week from now)
0
Comment
Question by:PeterErhard
5 Comments
 

Expert Comment

by:savsoft
Comment Utility
just use data type as date for date column then use simple query as mention .. It will work fine
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
If I'm understanding correctly, you can use mySQL's date functions to calculate the dates.

SELECT *
FROM     table
WHERE  DATE >= curDate()
AND       DATE <=  DATE_ADD(curDate(), INTERVAL 7 DAY)
0
 

Expert Comment

by:savsoft
Comment Utility
yes but use datatype as date for date column field
0
 
LVL 16

Expert Comment

by:Swadhin Ray
Comment Utility
Try this:

mysql> select * from table where date_column between  '2011-09-17'and  '2011-09-24';

mysql> Select * from tables where date > "2011-09-17' and CREATE_TIME < "2011-09-24";

0
 

Author Comment

by:PeterErhard
Comment Utility
Thanks for your help guys, _agx_'s was what I was most looking for.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now