Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 14th December 2024 11:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.