Trying to find the previous six days with any date

I use strtotime just fine to find the records of last week and next week in my database, but I can not find how to find the previous six days if the user selects the past date.

Here is how I know that today and the previous six days:

$today = date("Y-m-d");
$minus6 = date('Y-m-d', strtotime('-6 days'));

Now, how can I switch $ today with $ dateString, as provided by my users input? I thought this was similar to my google searches, but it did not produce any results:

$dateString = 2010-01-25; // for example
$minus6 = date('Y-m-d', strtotime('-6 days, $dateString');

Is there any fundamental information about dates, strtotime, or what? Thanks for any help.

+3
source share
2 answers

strtotime(). :

$dateString = 2010-01-25; // for example
$minus6 = date('Y-m-d', strtotime('-6 days, $dateString'));

: -

$dateString = "2010-01-25"; // for example
$minus6 = date('Y-m-d', strtotime("$dateString -6 days"));

... strtotime() .

+1

strtotime - , :

echo date('Y-m-d', strtotime('-6 days', strtotime($dateString));

.

+3

Source: https://habr.com/ru/post/1738560/


All Articles