“PHP сравните две даты” Ответ

PHP сравните две даты

$today = date("Y-m-d");
$expire = $row->expireDate; //from database

$today_time = strtotime($today);
$expire_time = strtotime($expire);

if ($expire_time < $today_time) { /* do Something */ }
Andean Goose

PHP сравните даты

$date_now = date("Y-m-d h:i:s");
$variable = new DateTime($date_now);
$to_compare = "2018-06-01 12:48:09";
$variable1 = new DateTime($to_compare);
$difference = date_diff($variable, $variable1)->format("Difference => %Y years, %m months, %d days, %h hours, and %i minutes");
echo $difference;
Programming Is Fun

PHP получить дату между двумя датами

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

//Which should get you an array with DateTime objects. 

//To iterate

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}
Funny Finch

Сравните даты DateTime PHP

$date1 = new DateTime("now");
$date2 = new DateTime("tomorrow");

var_dump($date1 == $date2); // false
var_dump($date1 < $date2); // true
var_dump($date1 > $date2); // false
Distinct Dotterel

PHP сравните даты

$date1 = "2021-01-15";
$date2 = "2021-01-18";

if ($date1 < $date2) {
 	echo "$date1 is earlier than $date2";
} else {
	echo "$date1 is later than $date2";
}
adgbe

Две дата столбца сравнивается в PHP

// Current timestamp is assumed, so these find first and last day of THIS month
$first_day_this_month = date('m-01-Y'); // hard-coded '01' for first day
$last_day_this_month  = date('m-t-Y');

// With timestamp, this gets last day of April 2010
$last_day_april_2010 = date('m-t-Y', strtotime('April 21, 2010'));
Wicked Wildebeest

Ответы похожие на “PHP сравните две даты”

Вопросы похожие на “PHP сравните две даты”

Больше похожих ответов на “PHP сравните две даты” по PHP

Смотреть популярные ответы по языку

Смотреть другие языки программирования