montymoose
Posts: 85
|
| Posted: 08/07/2007, 7:48 AM |
|
Hi,
I have a couple of date calculations which I need to use in my latest project. I've tried a number of SQL commands, but each seem to fail. If any of you SQL daddies have a few minutes spare, you could save me hours of messing about with scripts.
Problem 1:
I have a news database which now has many years of daily news each as individual records. I have been asked to provide a 'today in 2006' section which returns rows with a datestamp that matches the current date minus 1 year. so Today would pull any records with the date: 07/08/2006.
Problem 2:
I need to also return all records which have a date stamp which is not older than 3 weeks. The last 3 weeks worth of news if you like.
Thanks in advance,
John.
|
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 08/07/2007, 3:36 PM |
|
montymoose
I am going to assume that you are using MySQL. If this is the case then try using these MySQL functions in your where statement DATE_ADD(), DATE_SUB() and if you are using MySQL 4.1.1 you can use DATEDIFF().
NOTE: If you are new to MySQL I would suggest downloading thier CHM for MySQL it is a good reference to have for occassions like this.
|
 |
 |
montymoose
Posts: 85
|
| Posted: 08/08/2007, 12:58 AM |
|
Thanks,
|
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 08/08/2007, 4:53 PM |
|
montymoose
No problem, glad I could be of service .
|
 |
 |
|