Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

sanitize_date_field_input()

Parameters

ColumnTypeDefaultDescription
$date
$validate false

Location

include/resource_functions.php lines 7480 to 7513

Definition

 
function sanitize_date_field_input($date$validate=false)
    {
    
$year_input getval("field_" $date "-y","");
    
$year sprintf("%04d"$year_input);  // Assume CE year
    
if(strlen($year_input)==5) {
        
$year sprintf("%05d"$year_input);  // BCE year has leading -
    
}
    
$month  getval("field_" $date "-m","");
    
$day    getval("field_" $date "-d","");
    
$hour   getval("field_" $date "-h","");
    
$minute getval("field_" $date "-i","");

    
// Construct value, replacing missing parts with placeholders
    
$val  = ($year != "" && $year != "0000") ? $year "year";
    
$val .= "-" . ($month != "" $month "month");
    
$val .= "-" . ($day != "" $day "day");
    
$val .= " " . ($hour != "" $hour "hh");
    
$val .= ":" . ($minute != "" $minute "mm");
    if(
$validate)
        {
        
# Format dates for the date validator e.g. 2020, 2020-month-29 by stripping unused placeholders
        
$removedates = array("year-month-day","-month-day","-day"," hh:mm");
        
$val str_replace($removedates,"",$val);
        }
    else
        {
        
# Format for database entry e.g. 2020-00-00, 2020-00-29, if nothing is set replace with a null string
        
$removedates = array("year-month-day hh:mm","year","month","day"," hh:mm","hh","mm");
        
$subdates = array("","0000","00","00","","00","");
        
$val str_replace($removedates,$subdates,$val);
        }

    return 
$val;
    }

This article was last updated 19th March 2024 09:05 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.