Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have this query:

"SELECT * FROM `" . $table . "` WHERE STR_TO_DATE(data, '%d/%m/%Y')=(SELECT max(STR_TO_DATE(data, '%d/%m/%Y')) FROM " . $table . ")
    AND hour=(SELECT MAX(hour)-".$delta_hour."
 FROM  `" . $table . "` WHERE STR_TO_DATE(data, '%d/%m/%Y')=(SELECT max(STR_TO_DATE(data, '%d/%m/%Y')) FROM " . $table . ")) 
 ORDER BY `" . $table . "`.`cell`  ASC"

Where:
$table - My table;
$delta_hour - hours ago;

I have to create a method getRecords($table, 12) where 12 is $delta_hour(12 hours ago);
If the result is zero then I have to use the same method, but using 24 as $delta_hour.

I can't understand how to change the DATE.

share|improve this question
add comment

1 Answer 1

Must date and time be in separate fields? If not, perhaps you can convert the two fields into one DATETIME field, and use DATE math on it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.