strtotime using string "first day of last week" not correct
Discuss coding issues, and scripts related to PHP and MySQL.
-
Marius
- Posts: 107
strtotime using string "first day of last week" not correct
Using the code:
Code: Select all
$from_date = date('Y-m-d 00:00:00', strtotime('first day of last week'));
echo $from_date; // 2020-10-01 00:00:00
returns: "2020-10-01 00:00:00", when I expect it to return "2020-10-25 00:00:00".
Why is it returning the first day of the month?
How can I get the
first day of last week (and also the
last day of last week)?
Admin
To get in php the "
first day of last week", try strtotime() with the string: "
last week last sunday".
To get the "
last day of last week", use the phrase: "
last day of last week".
Code: Select all
$first_day = date('Y-m-d 00:00:00', strtotime('last week last sunday'));
$last_day = date('Y-m-d 00:00:00', strtotime('last day of last week'));
echo $first_day; // 2020-10-25 00:00:00
echo $last_day; // 2020-11-30 00:00:00
Similar Topics
-
Adding string from database into PDF
PHP - MySQL
First post
Hello Coursesweb I have a problem with my php document to convert it to PFD
I cant find out how to get results from $users into the HTML to the PDF...
Last post
Thanks MarPlo I prefer not to ask anything on stackoverflow.com
because I once typed a small i instead of I.
and received many comments about it....
-
Remove backslash from string
PHP - MySQL
First post
How can I remove backslashes from string in php?
I tried the following code.
$str ='abc-\123';
$str = stripcslashes($str);
echo $str; //...
Last post
You can use str_ireplace() to remove backslash from string in php, but like in the following code (add two backslashes into the removing argument):...
-
Check for an array of words in a string in php
PHP - MySQL
First post
I have a list of spam words that are into an array. When a user submits a string text, I want to know if it contains these words. How can I do this...
Last post
You could add the spam words into a string, with | as word separator and then use regular expression to check.
$my_words =...
-
Move the string that matches the regex to the end
JavaScript - jQuery - Ajax
First post
I have the following problem to solve it in JavaScript:
- Find the text which is between small brackets and shift that text with the brackets to...
Last post
Try the following code:
function testToEnd(str){
//get matched string
let st = str.match(/ *\( +\) */g)
if(st){
st = st ;
// replace the...
-
Extract number and periods from string in php
PHP - MySQL
First post
I have a string with numbers and periods. For example '123456...'
I want to separate 123456 and ... and still get the number and the period in php....
Last post
It's because the dot (.) in regex is any character, while \. is literal dot.
Try the following code:
$matches = null;
$input = '123456...';...