Query with a specified date - PHP

Asked

Viewed 82 times

-1

Hello, I have an order query, where I just wanted to show the orders of the current day and also the orders of the next day, where the orders of the next day would only appear those that would have to be delivered at 8 am.

  • 2

    What is your doubt?

  • What have you tried? Put here the code you already have and describe what problem is happening. So we can help.

1 answer

-1


//Query para os pedidos do dia
$pedidos_do_dia = 'select * from pedidos where data_pedido = CURDATE();';

//Query para os pedidos de amanha
// $amanha = date("Y")+"-"+date("d")+"-"+date("d")+" 08:00:00" 
# linha com o concatenador errado

$amanha = date("Y")."-".date("m")."-".(date("d")+1)." 08:00:00" 
//Linha com o concatenador correto

$pedidos_amanha = "select * from pedidos where data_pedido = $amanha;";

Now just run the selects and show the results where you want.

  • I tried to use the code you gave me, but it didn’t work. This picking up the orders of the current day but the question of picking up the orders of the next day scheduled for 8 am is not working. Look what I did:

  • $amanha = date("Y")+"-"+date("d")+"-"+date("d")+" 08:00:00"; $sql_sel_orders ="SELECT requests. *, customers.Name AS clientenome, deliverymen.id AS identregador FROM orders LEFT JOIN customers ON customers.id=orders.clients_id_sender LEFT JOIN deliverymen ON deliverymen.id=orders.deliverers_id WHERE (orders.status='0' AND ordering.terceirizadas_id='". $sql_sel_terceirizadas_dados['id']." ') AND (pedidos.data= CURDATE() OR pedidos.data='". $amanha."')) ";

  • when giving echo in the variable $tomorrow, appears the following 2031, maybe this is the mistake.

  • Sorry, confusion of language, I used + as concatenator, and this is valid for javascript and not for php that uses '.', change the concatenator.

  • Okay, thank you very much!!! follow the code to verify. $amanha = date("Y")." -". date("m")." -". (date("d")+1)"" ; $sql_sel_orders ="SELECT orders. *, customers.name AS clientname, deliverymen.id AS sender FROM orders LEFT JOIN customers ON customers.id=orders.clients_id_sender LEFT JOIN deliverymen ON deliverymen.id=orders.deliverym_id WHERE orders.status='0' AND ordering.outsourced_id='". $sql_sel_terceirizadas_dados['id']." ' AND (pedidos.data=CURDATE() OR (pedidos.data='". $amanha." ' AND pedidos.horario='08:00:00'))";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.