andrew
andrew

Reputation: 2098

mysql comparing intergers

I was wondering if i can compare two intergers in my sql statement. I have one date field, saved as unixtimestamp. I want to find those records where the date field is between two values. Something like this:

Select ... From ... WHERE (dateField + myNumber) Between (x) And (y)

where myNumber is a variable from a loop function.

Is something like this possible?

Edit: myNumber is always a positive number, greater than the datefield value

What i am trying to do is create a list of events that must happen again at some point in the future. I have some records of logged events in my table. I run a query to find when those events must happen again in the future.

Lets say that i have 10 records that happened on March, 2011, I need to create a list of those 10 records that must happen again in March, 2012.

That's why i thought of the logic: [saved_date] + [1 year duration] Between [March 1, 2012] And [March 31, 2012]

It seemed simple enough since my dates are stored as unix timestamps.

Upvotes: 1

Views: 71

Answers (1)

Bohemian
Bohemian

Reputation: 425053

I'd be inclined to not modify the field, but rather modify the range values, so you can still use an index (if one exists):

Select ... From ... WHERE dateField Between x - myNumber And y - myNumber

Upvotes: 3

Related Questions