1

I have database "raj" with table "pagination"

In table pagination have "id", "actualtime" and "created" field

id - auto_increment
name- varchar
created- datetime

I want to display all rows which is created on todays date display upto yesterdays 06:00 pm.after that the content will be refreshed based on based on a DATETIME field called 'created' that holds the date and time of each record's creation.

this is my query to fetch rows but it is not working properly...plz help me......

$sql = "
    SELECT name 
    FROM pagination where created >= DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)
       ";
  • 1
    And how is it not working properly? Does it generate an error? Does it return results that you are not expecting? – mustaccio Sep 10 '14 at 14:33
  • yes it does not return expected result... – user3821226 Sep 10 '14 at 14:57
  • i need a query to display data from today date till 06:00 pm yesterday.... after that the content will be refreshed.plz help me.... – user3821226 Sep 10 '14 at 14:58
2

This is the expression for 6:00 PM yesterday

SELECT DATE(NOW()) - INTERVAL 6 HOUR;

Craft the SELECT with that expression

SELECT * FROM pagination WHERE
created >= DATE(NOW()) - INTERVAL 6 HOUR;

Give it a Try !!!

1

Default current_Date or curdate gives the date as if YYYY-MM-DD 00:00:00, making the time as PM will help your query

SELECT name
FROM pagination 
WHERE created >= DATE_SUB(DATE_ADD(CURDATE(),INTERVAL 18 HOUR),INTERVAL 1 DAY)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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