sql_date_proche

The sql_date_proche() function is used to return a conditional expression for a column in relation to a date.

It accepts 5 parameters:

  1. $champ is the SQL column to be compared,
  2. $interval is the comparison interval value: -3, 8, ...
  3. $unite is the units of reference (’DAY’, ’MONTH’, ’YEAR’, ...)
  4. $serveur,
  5. $option.

It is used as shown below:

  1. $ifdate = sql_date_proche('column', -8, 'DAY');
  2. $res = sql_select('column', 'table', $ifdate);

Download

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:

  1. $row = sql_fetsel(
  2. array("*", sql_date_proche('en_ligne', -15, 'DAY') . " AS recently"),
  3. "spip_auteurs",
  4. "id_auteur=$id_auteur");
  5. // $row['recently'] : true / false

Download

Author Mark Baber Published : Updated : 02/06/10

Translations : English, français