O
O
ololodff2022-02-12 13:31:58
SQL
ololodff, 2022-02-12 13:31:58

Why doesn't BETWEEN produce a sample within the specified range?

I have 2 dates (the beginning of the last week and the end of the last week) I want to make a selection for the last week by date:

$start_pned = strtotime("last monday midnight");
$end_pned = strtotime("-1 week",$start_pned);

$starts_pned = date("Y-m-d",$start_pned);
$ends_pned = date("Y-m-d",$end_pned);


Above in the code, I get 2 dates in the format 2022-02-12, etc.
Now I make a request to the database, like this:
dates BETWEEN '$ends_pned' AND '$starts_pned'

But the result is not everything that was added over the past week, but everything starting from the last week and up to the current date.
Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2022-02-12
@FanatPHP

Before messing around with php, you first need to get a working query in SQL
. And only after the query works in the console, transfer it to php.
Now we have no idea at all where the krivoruchko is here - in the database, in the request, in the PHP shit code.
If the question is about between, then it should not contain any PHP.
And there should be sql, and entirely , and not some kind of stub.
And at the same time an example of data from the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question