John Davidson

php strtotime 'third day of + 1 month' = false

0 comments
Message:


I want a loop like this:


This loop is OK:


while($d<=$d2) {  
$x = "first day of + 1 month";
$d=strtotime($x,$d);
do_something($d);
}

But


while($d<=$d2) {  
$x = "third day of + 1 month";
$d=strtotime($x,$d);
do_something($d);
}

doens't work: https://www.functions-online.com/strtotime.html gives "false"
How can I solve this?


(first, second, third etc is a variable)



My Answer:
The strtotime() function in PHP is used to convert a date/time string into a Unix timestamp. It can parse a wide variety of date/time formats and return the timestamp representing the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Here is an example of how to use strtotime():

php
$dateString = "2022-12-31";
$timestamp = strtotime($dateString);

echo $timestamp; // Output: 1672473600


In this example, the strtotime() function is used to convert the date string "2022-12-31" into a Unix timestamp. The resulting timestamp represents December 31, 2022, at midnight.

Rate this post

3 of 5 based on 8709 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us