Solved

Date within mySQL query

Posted on 2011-09-16
5
321 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
ID: 36553248
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
ID: 36553259
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
ID: 36553262
yes but use datatype as date for date column field
0
 
LVL 16

Expert Comment

by:Swadhin Ray
ID: 36553268
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
ID: 36553929
Thanks for your help guys, _agx_'s was what I was most looking for.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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