Faq/Base/121/da

    From The Document Foundation Wiki
    < Faq‎ | Base
    This page is a translated version of the page Faq/Base/121 and the translation is 91% complete.
    Outdated translations are marked like this.


    Hvordan kan jeg beregne en alder ud fra en fødselsdato?

    • Givet et felt, der indeholder fødselsdage, beregn aktuel alder.

    Aldersberegning, resultater på formen "xx år"

    Forespørgslen skal være

    SELECT "DateNaissance", 
    CASE WHEN MONTH(CURRENT_DATE) < MONTH("DateNaissance") OR ( MONTH(CURRENT_DATE) = MONTH("DateNaissance") AND DAY(CURRENT_DATE) < DAY("DateNaissance") ) 
    THEN CAST((YEAR(CURRENT_DATE) - YEAR("DateNaissance") -1) AS VARCHAR) || ' ans' 
    ELSE CAST((YEAR(CURRENT_DATE) - YEAR("DateNaissance") ) AS VARCHAR) || ' ans'END AS "Age"FROM "Table1"

    For at beregne alder på den nærmeste dag:

    Eksempel beregnet den 02/07/2011

    Forespørgslen ser sådan ud

    SELECT "DateNaissance", "Nom", YEAR(NOW())-YEAR("DateNaissance")-
    CASE WHEN (MONTH( NOW() ) < MONTH("DateNaissance") OR ( MONTH( NOW() ) = MONTH("DateNaissance") AND 
    DAY( NOW() ) < DAY ("DateNaissance"))) THEN 1 ELSE 0 END AS "ans", 
    MONTH(NOW())-MONTH("DateNaissance") +
    CASE WHEN MONTH(now()) <= MONTH("DateNaissance") AND DAY(NOW()) < DAY("DateNaissance")
    THEN 11 ELSE
    CASE 
    WHEN MONTH(NOW()) < MONTH("DateNaissance") AND DAY(NOW()) >= DAY("DateNaissance")
    THEN 12 ELSE
    CASE WHEN MONTH(NOW()) > MONTH("DateNaissance") AND DAY(NOW()) < DAY("DateNaissance")
    THEN -1 ELSE 0
    END
    END
    END AS "mois", 
    DATEDIFF('DAY', CAST(YEAR(NOW()) || '-' || RIGHT( 0 || MONTH(NOW())  - casewhen DAY(NOW()) < DAY("DateNaissance")
    THEN 1 ELSE 0
    END, 2) || '-' || RIGHT( 0 || DAY("DateNaissance"), 2) AS DATE) , NOW() ) AS "jours" FROM "Table1"