Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2010, 08:20 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Minus 1 Day and Year range

Hi all,

If there any best ways we had to code in Mysql :-

-- minus 1 YEAR range if today 2010-10-23
SELECT me FROM them
WHERE them.you > '2009-10-22' AND them.you < '2010-10-23'


-- minus 1 DAY range if today 2010-10-23
SELECT me FROM them
WHERE them.you > '2010-10-22' AND them.you < '2010-10-23'


Thanks.
 
Old October 22nd, 2010, 08:28 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
SELECT me FROM them 
WHERE you > CURDATE() 
AND you  < DATE_ADD( DATE_ADD( CURDATE(), INTERVAL 1 YEAR ), INTERVAL 1 DAY )
 
Old October 23rd, 2010, 11:46 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Red face

Thanks for your kindness Old Pedant,

I did it as yours where I want to have 1 Year range between 2009 till 2010 holding yesterday date:-

SELECT me FROM them
WHERE you > DATE_ADD( DATE_ADD( CURDATE(), INTERVAL -1 YEAR), INTERVAL -1 DAY) AND you < CURDATE()


regards..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Determine the first day of the current Fiscal Year tcarnahan Oracle 3 February 16th, 2009 09:52 PM
Using month & year variable to get date in range rsearing ASP.NET 2.0 Professional 2 July 5th, 2008 08:30 AM
MINUS / EXCEPT in MS Access d-fxt Access 2 March 8th, 2007 06:09 PM
get year,month,day,hour... kobystud C# 1 July 16th, 2004 04:45 PM
day to day use of XML mano XML 1 November 27th, 2003 01:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.