Connecting Tech Pros Worldwide Forums | Help | Site Map

date subtraction calculations

seshu's Avatar
Familiar Sight
 
Join Date: Nov 2006
Location: Hyderabad,India
Posts: 156
#1: Feb 2 '07
Hi Everybody
This is seshu yester day i found a unexpected problem that is with dates actualy i wrote a code to get the values of yesterday by writing a code like this
select * from table where order_date=current_date-1
earlier it was workling as the days were not the first date of mounth yesterday as it was 1st feb i could able to make it out that to after deploying for that reason i have not installed it yesterday and has installed it today but iam sure that the same problem will arrais after one mounth so can any one say me a permenent solution
thanking you
regards
seshu

Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#2: Feb 2 '07

re: date subtraction calculations


Quote:

Originally Posted by seshu

Hi Everybody
This is seshu yester day i found a unexpected problem that is with dates actualy i wrote a code to get the values of yesterday by writing a code like this
select * from table where order_date=current_date-1
earlier it was workling as the days were not the first date of mounth yesterday as it was 1st feb i could able to make it out that to after deploying for that reason i have not installed it yesterday and has installed it today but iam sure that the same problem will arrais after one mounth so can any one say me a permenent solution
thanking you
regards
seshu

What you actually want to do, is use the DATE_SUB() function:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE order_date = DATE_SUB(CURDATE(),INTERVAL 1 DAY)
  2.  
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Feb 2 '07

re: date subtraction calculations


Date calculations are not jus plain arithmetic! You'll have to use the MySQL date_sub() function.

Ronald :cool:
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#4: Feb 2 '07

re: date subtraction calculations


Quote:

Originally Posted by ronverdonk

Date calculations are not jus plain arithmetic! You'll have to use the MySQL date_sub() function.

Ronald :cool:

Beat you to it Ronald!
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#5: Feb 2 '07

re: date subtraction calculations


Quote:

Originally Posted by Motoma

Beat you to it Ronald!

Photo finish!

Ronald
seshu's Avatar
Familiar Sight
 
Join Date: Nov 2006
Location: Hyderabad,India
Posts: 156
#6: Feb 3 '07

re: date subtraction calculations


thank you sir i dint check the code yet but i think i will work well the moment it is impleemented i will report to you
thanking you
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#7: Feb 7 '07

re: date subtraction calculations


So, seshu?? Have you implemented and tested it?
You promised us to come back on this!

Ronald :cool:
seshu's Avatar
Familiar Sight
 
Join Date: Nov 2006
Location: Hyderabad,India
Posts: 156
#8: Feb 8 '07

re: date subtraction calculations


hi sir iam really sorry that i could nt come bak immedeiatly as i have a problem with net connection at home
now coming to the querry that was working if the interval is 1 but it is not workiking on 15
see the querry i wrote is like this
SELECT * FROM table WHERE order_date = DATE_SUB(CURDATE(),INTERVAL 20 DAY)
i am sure that there is a record on 25th of last month

waiting for ur reply

regards
seshu
seshu's Avatar
Familiar Sight
 
Join Date: Nov 2006
Location: Hyderabad,India
Posts: 156
#9: Feb 8 '07

re: date subtraction calculations


sorry iam able tofind the code here in this manner
but later i was having a small problem with date interval for thet i have strugled for one more hour using ur querry finally i found the result with the querry below

SELECT * FROM accchanges WHERE date(cdate) between DATE_SUB(CURDATE(),INTERVAL 20 DAY) and current_date

hope you must be knowing this code but i think this will be helpfull to someone else
and once again thanks for giving a right piece of code at right time
regards
seshu
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#10: Feb 8 '07

re: date subtraction calculations


Thank you for posting your success back to us seshu!
Reply


Similar MySQL Database bytes