简体   繁体   中英

Select between two times and dates in SQL PHP

I am trying to find a way to select the row from database which the dates are between yesterday 5p.m. and today 4:59p.m.

The database are filled with orders and I am trying to make it display all the orders starting from yesterday's 5p.m. till today's 4:59p.m. I have to make it display those entries everyday so that my client is able to know what had been ordered today until the cut-off time.

I had found a few but only display time from 0000 - 23:59 while what I need is 17:00 - 16:59.

Is there any way to do so?

EDIT:

The query that I had so far:

"SELECT date FROM xcart_orders WHERE date between '".strtotime(date("F j, Y", time() - 60 * 60 * 24))."'  and '".strtotime(date('F j, Y'))."'"

This will return me result between now and yesterday. Eg Currently is 12PM, it will return me the results from yesterday 12PM till now(12PM).

HOWEVER, what I want is it will always show me the result from yesterday 5PM till today 4:59PM. This is necessary as my client is doing e-commerce and the cut-off time for delivery is 5PM. Hence, he needs to consolidate the orders from last cut-off time to current cut-off time .

My apologies for forgetting to inform about this; the date in the database is in UNIX time stamp , hence, my query has 'strtotime'.

Sorry causing confusion, my English isn't good.

Regards, FT

Check this and try

$yesterday= date("Y-m-d", time()-86400)." 00:00:00";
$yesterday2= date("Y-m-d", time()-86400)." 23:59:59";

Change the time if you like

Try this

SELECT x FROM y WHERE date between '2014-05-07 08:00' and date_add('2014-05-07 08:00', INTERVAL 1 DAY)

The result should be every data you select from date 2014-05-07 8am to 2017-05-08 7.59am

Hope it helps. =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM