ID EN
#Date and time

DATEDIF

Excel Functions 🇮🇩 Bahasa Indonesia

Dapatkan hari, bulan, atau tahun di antara dua tanggal

Syntax

EXCEL
=DATEDIF(start_date, end_date, unit)

Arguments

Parameter Deskripsi
start_date Start date in Excel date serial number format.
end_date End date in Excel date serial number format.
unit The time unit to use (years, months, or days).

Return Value

Waktu antara dua tanggal dalam satuan tertentu

Details

Fungsi DATEDIF menghitung selisih antara dua tanggal dalam tahun, bulan, atau hari. Hasilnya selalu berupa bilangan bulat, karena DATEDIF membulatkan ke bawah hingga interval penuh terakhir. Interval yang diinginkan dikendalikan oleh argumen unit, yang mendukung enam kode teks seperti yang ditunjukkan pada tabel di bawah ini: Tiga unit pertama ("y", "m", "d") mengembalikan total interval. Tiga interval terakhir ("ym", "yd", "md") mengembalikan interval yang tersisa, yang berguna untuk membagi waktu yang telah berlalu menjadi beberapa komponen. Misalnya, untuk menyatakan durasi sebagai "X tahun, Y bulan, Z hari", Anda akan menggunakan "y" untuk tahun, "ym" untuk sisa bulan, dan "md" untuk sisa hari. Status DATEDIF di Excel agak misterius. DATEDIF (Tanggal + Dif) adalah fungsi "kompatibilitas" yang berasal dari Lotus 1-2-3 pada tahun 1990an. Alth

Contoh

Basic usage
EXCEL
=DATEDIF("1-Jan-2023","1-Mar-2025","y") // returns 2 (complete years)
=DATEDIF("1-Jan-2023","1-Mar-2025","m") // returns 26 (complete months)
=DATEDIF("1-Jan-2023","1-Mar-2025","d") // returns 790 (total days)
=DATEDIF("1-Jan-2023","1-Mar-2025","ym") // returns 2 (months after years)
=DATEDIF("1-Jan-2023","1-Mar-2025","yd") // returns 59 (days after years)
=DATEDIF("1-Jan-2023","1-Mar-2025","md") // returns 0 (days after months)
Difference in days

DATEDIF can calculate the difference between dates in days in three ways, using the "d", "yd", and "md" units. In the worksheet below, the goal is to

EXCEL
=DATEDIF(B5,C5,"d") // total days
=DATEDIF(B5,C5,"yd") // days ignoring years
=DATEDIF(B5,C5,"md") // days ignoring months and years
Difference in months

DATEDIF can calculate the difference between dates in months in two ways, using the "m" and "ym" units. In the worksheet below, the goal is to calcula

EXCEL
=DATEDIF(B5,C5,"m") // complete months
=DATEDIF(B5,C5,"ym") // months ignoring years
Difference in years

DATEDIF calculates the difference between dates in complete years with the "y" unit. In the worksheet below, the goal is to calculate the number of co

EXCEL
=DATEDIF(B5,C5,"y") // complete years
Years, months, and days between dates

DATEDIF's ability to return different time components makes it ideal for expressing elapsed time as a combination of years, months, and days. In the w

EXCEL
=DATEDIF(B5,C5,"y") // years
=DATEDIF(B5,C5,"ym") // months
=DATEDIF(B5,C5,"md") // days
Years, months, and days between dates

Together, the three results add up to the total time elapsed between the start date and end date. To display time elapsed as a single result like "X y

EXCEL
=DATEDIF(B5,C5,"y")&" years, "&DATEDIF(B5,C5,"ym")&" months, "&DATEDIF(B5,C5,"md")&" days"

See Also

DAYS NETWORKDAYS YEARFRAC TODAY EDATE DATE