Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 190 to 225

Definition

 
function check_date_format($date)
    {
    global 
$lang;

    if (
is_null($date)){$date="";}
    
    
// 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))
        
// Check the format of the date to "yyyy-mm-dd hh:mm"
        
|| (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})$/"$date$parts))
        
// Check the format of the date to "yyyy-mm-dd"
        
|| (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 19th March 2024 02:05 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.