Trying to figure out how to do math in sql queries related to time stamps
I need to do some math around a time stamp in a column in a mysql
database. I am using these queries within PHP to extrapolate values, then
using them as variables to feed into another function that generates a
highcharts graph.
So for example:
SELECT COUNT(blah) FORM blah WHERE start_stamp >=now() - interval 1 day
but then I need to subtract from another value from a similar query to get
the the count from the previous day, like:
SELECT COUNT(blah) FORM blah WHERE start_stamp >=now() - interval 2 day
So let's say these two become variables $today and $yesterday, how can I
do this most effectively within a SQL query? Obviously I can do the math
within PHP but I am sure there is a better way to do this within the query
itself.
No comments:
Post a Comment