ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:month

month

From Version 5.21.0-beta-2

See Also

day()
year()

Syntax
string month(
    string $fieldName,
)

Description

The method month() is a helper routine that simplifies the creation of an oft-used SQL statement to obtain just the month of a specified date/time field as a 2 digit number (MM). If the value of the month is less than 10, it is zero padded. This allows for correct sorting.

Parameters

$fieldName

The date/time fieldname to be processed


Usage

In the following example, we analyze the most often occurring month of the year for a birth date

$sql = "SELECT {$db->month('birth_date')},COUNT(employees.*)
          FROM employees
          GROUP BY {$db->month('birth_date')}
          ORDER BY {$db->month('birth_date')} DESC";
$data = $db->getRow($sql); 
 
/*
* Returns 14 employees have their birth date on the 8th
* month of the year
*/
 
array(0=>array(0=>08,
               1=>14))
 
*/
v5/reference/connection/month.txt · Last modified: 2022/08/22 12:50 by dregad