DATEDIF - Date Difference

  • Last update: May 21, 2025
  • Overview

    Syntax

    DATEDIF(text/start_date,text/end_date,unit)

    Returns the number of days, months, or years between two specified dates.

    Parameter 1

    Text/start_date

    start_date represents the starting date of the specified period.

    end_date represents the ending date of the specified period.

    Parameter 2

    Text/end_date

    Parameter 3

    Unit

    Represents the type of information returned by the function.

    • If the unit is Y or y, the year difference is returned.

    • If the unit is M or m, the month difference is returned.

    • If the unit is W or w, the week difference is returned.

    • If the unit is D or d, the day difference is returned.

    • If the unit is MD or md, the day difference (ignoring the year and month) is returned.

    • If the unit is YM or ym, the month difference (ignoring the year and day) is returned.

    • If the unit is YD or yd, the day difference (ignoring the year) is returned.

    • If the unit is H or h, the hour difference (ignoring the year) is returned.

    • If the unit is MI or mi, the minute difference (ignoring the year) is returned.

    • If the unit is S or s, the second difference (ignoring the year) is returned.

    The unit is required to be a constant. Field references are not supported, but direct parameter input is allowed.

    iconNote:

    1. FineDataLink of V4.0.30 and later versions support the calculation of the difference in weeks/hours/minutes/seconds between two specific dates using the DATEDIF() function. If the difference is less than one week/hour/minute/second, the result is 0.

    2. If you want to calculate the number of months between two specified dates and avoid discarding the part when it's less than one month, you can use the months_between() function of Spark SQL.

    Notes

    • If any parameter is NULL, the result is NULL.

    Example

    FormulaResultNote

    DATEDIF("2001/2/28","2004/3/20","Y")

    3, indicating that there are three full years between February 28, 2001 and March 20, 2004.


    DATEDIF("2001/2/28","2004/3/20","M")

    37, indicating that there are 36 full months between February 28, 2001 and March 20, 2004.


    DATEDIF("2001/2/28","2004/3/20","D")

    1116, indicating that there are 1116 full days between February 28, 2001 and March 20, 2004.


    DATEDIF("2001/2/28","2004/3/20","md")

    8, indicating that there are 8 full days (ignoring the month and year) between February 28, 2001 and March 20, 2004.


    DATEDIF("2001/1/28","2004/3/20","YM")

    2, indicating that there are 2 full months (ignoring the month and day) between January 28, 2001 and March 20, 2004.


    DATEDIF("2001/2/28","2004/3/20","yd")

    21, indicating that there are 21 full days (ignoring the year) between February 28, 2001 and March 20, 2004.


    To calculate the number of days between two date-type fields (for example, Order_ Date and Shipped_Date), add a field and use the formula DATEDIF(Order_Date,Shipped_Date,"D"), as shown in the following figure.

    3-1.png

    The calculated date difference is shown in the following figure.

    3-2.png

    附件列表


    主题: Data Development - Scheduled Task
    Previous
    Next
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy