Welcome on my blog

We use cookies to ensure you get the best experience on our website.

PHP – Czy data jest w podanym okresie, od 1 danego miesiąc do 2’th wtorku danego miesiaca

Autor: chmajster 11.07.2024
<?php
function isDateInRange($tmpDate, $startDate, $endDate) {
    // Convert dates to DateTime objects for easier comparison
    $date = new DateTime($tmpDate);
    $startDate = new DateTime($startDate);
    $endDate = new DateTime($endDate);

    // Check if the date is within the range
    return ($date >= $startDate && $date <= $endDate);
}

// Example usage
$tmpDate = '2024-07-10';
$startDate = new DateTime((new DateTime($tmpDate))->format('Y-m-01'));
$endDate = '2024-07-15';

if (isDateInRange($tmpDate, $startDate->format('Y-m-d'), $endDate)) {
    echo "The date $tmpDate is within the range from " . $startDate->format('Y-m-d') . " to $endDate.";
} else {
    echo "The date $tmpDate is not within the range from " . $startDate->format('Y-m-d') . " to $endDate.";
}
?>

Tagi: php
Dodaj komentarz

Search
Categories
O Blogu

Cześć Podróżniku!

Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.

Buy me A coffee
[Empty]

Wszelkie prawa zastrzeżone