select value between particular date and time schedule

I have database “raj” with table “pagination”

In table pagination have “id”, “actualtime” and “created” field

id - auto_increment actualtime- varchar created- datetime

that looks like this CREATE TABLE pagination( id int auto_increment, actualtime varchar(55), created datetime )

I want to display all rows which are created on todays date and will display from today upto yesterday at 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 display value after 06:00 pm on yesterday but i want to display all data before 06:00 pm from currentdate. After 06:00 pm data will be refreshed and clear. plz help me…

SELECT actualtime FROM pagination WHERE created BETWEEN date_add(date_sub(curdate(), INTERVAL 1 day), INTERVAL 18 hour) AND curdate()";

Just break it down

[php]SELECT actualtime FROM pagination WHERE created = curdate(); [/php]

That should get all records from the current day…

Now you need to add an AND clause to get it where the hour is less then 6 pm

[php]SELECT actualtime FROM pagination WHERE created = curdate() AND HOUR(created, %H) <=18 [/php]

Hour is a function on a 24 Hour scale, so 18 will be 6 PM…

I didn’t test this SQL, it’s just off the top of my head, but all you need to do is break the problem down a little differently then what you were doing.

Sponsor our Newsletter | Privacy Policy | Terms of Service