public static function getDateTime($value, $allowCompoundFormats = false, $dateFormat = 'Y-m-d')
    {
        /*
         * Empty value?
         * Nothing to do :)
         */
        if (empty($value)) {
            return false;
        }

        /*
         * Instance of DateTime class?
         * Nothing to do :)
         */
        if ($value instanceof DateTime) {
            return $value;
        }

        try {
            try {
                /*
                 * Pass the value to the constructor. Maybe it's one of the allowed relative formats.
                 * Examples: "now", "last day of next month"
                 */
                $date = new DateTime($value);

                /*
                 * Instance of the DateTime class was created.
                 * Let's verify if given value is really proper date.
                 */
                $dateFromFormat = DateTime::createFromFormat($dateFormat, $value);

                if (false === $dateFromFormat) {
                    /*
                     * Nothing to do more, because:
                     * a) instance of the DateTime was created
                     * and
                     * b) if createFromFormat() method failed, given value is one of the allowed relative formats
                     * ("now", "last day of next month")
                     * and...
                     */
                    if ($allowCompoundFormats) {
                        /*
                         * ...and
                         * c) it's not an integer, e.g. not 10 or 100 or 1000
                         */
                        if (!is_numeric($value)) {
                            return $date;
                        }
                    } else {
                        $specialFormats = [
                            'now',
                        ];

                        /*
                         * ...and
                         * c) it's special compound format that contains characters that each may be used by
                         * DateTime::format() method and it raises problem while trying to verify the value at the end
                         * of this method:
                         *
                         * (new DateTime())->format($value);
                         *
                         * So, I have to refuse those special compound formats if they are not explicitly declared as
                         * compound (2nd argument of this method, set to false by default)
                         */
                        if (in_array($value, $specialFormats, true)) {
                            return false;
                        }
                    }
                } /*
                 * Verify instance of the DateTime created by constructor and by createFromFormat() method.
                 * After formatting, these dates should be the same.
                 */
                else {
                    if ($dateFromFormat->format($dateFormat) === $value) {
                        return $date;
                    }
                }
            } catch (\Exception $exception) {
                if (!$allowCompoundFormats) {
                    return false;
                }
            }

            /*
             * Does the value is a string that may be used to format date?
             * Example: "Y-m-d"
             */
            $dateString = (new DateTime())->format($value);

            if ($dateString !== (string)$value) {
                return new DateTime($dateString);
            }
        } catch (\Exception $exception) {
        }

        return false;
    }