The
sql_date_proche()
function is used to return a conditional expression for a column in relation to a date.
It accepts 5 parameters:
-#
$champ
is the SQL column to be compared,
-#
$interval
is the comparison interval value: -3, 8, ...
-#
$unite
is the units of reference (’DAY’, ’MONTH’, ’YEAR’, ...)
-#
$serveur
,
-#
$option
.
It is used as shown below:
$ifdate = sql_date_proche('column', -8, 'DAY');
$res = sql_select('column', 'table', $ifdate);
Example
Another use for a selection query such as illustrated below, is to store the boolean result in an alias. The alias
recently
indicates whether or not an author has logged in during the last 15 days:
$row = sql_fetsel(
array("*", sql_date_proche('en_ligne', -15, 'DAY') . " AS recently"),
"spip_auteurs",
"id_auteur=$id_auteur");
// $row['recently'] : true / false