Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

check_date_format()

Description

Check date conforms to "yyyy-mm-dd hh:mm" format or any valid partital of that e.g. yyyy-mm.

Parameters

ColumnTypeDefaultDescription
$date
string string form of the date to check

Return

string

Location

include/metadata_functions.php lines 191 to 237

Definition

 
function check_date_format($date)
    {
    global 
$lang;

    
// Check the format of the date to "yyyy-mm-dd hh:mm:ss"
    
if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/"$date$parts))
        {
        if (!
checkdate($parts[2], $parts[3], $parts[1]))
            {
            return 
str_replace("%date%"$date$lang["invalid_date_error"]);
            }
        return 
str_replace("%date%"$datecheck_date_parts($parts));
        } 
    
// Check the format of the date to "yyyy-mm-dd hh:mm"
    
elseif (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})$/"$date$parts))
        {
        if (!
checkdate($parts[2], $parts[3], $parts[1]))
            {
            return 
str_replace("%date%"$date$lang["invalid_date_error"]);
            }
        return 
str_replace("%date%"$datecheck_date_parts($parts));
        } 
    
// Check the format of the date to "yyyy-mm-dd"
    
elseif (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/"$date$parts))
        {
        if (!
checkdate($parts[2], $parts[3], $parts[1]))
            {
            return 
str_replace("%date%"$date$lang["invalid_date_error"]);
            }
        return 
str_replace("%date%"$datecheck_date_parts($parts));
        } 
    
// Check the format of the date to "yyyy-mm" pads with 01 to ensure validity
    
elseif (preg_match("/^([0-9]{4})-([0-9]{2})$/"$date$parts))
        {
        
array_push($parts'01');
        return 
str_replace("%date%"$datecheck_date_parts($parts));
        } 
    
// Check the format of the date to "yyyy" pads with 01 to ensure validity
    
elseif (preg_match("/^([0-9]{4})$/"$date$parts))
        {
        
array_push($parts'01''01');
        return 
str_replace("%date%"$datecheck_date_parts($parts));
        } 

    
// If it matches nothing return unknown format error
    
return str_replace("%date%"$date$lang["unknown_date_format_error"]);
    }

This article was last updated 25th November 2020 07:35 Europe/London time based on the source file dated 11th September 2020 17:00 Europe/London time.