ID EN
Date and Time Functions

TO_DAYS(date)

MySQL 8.4 🇮🇩 Bahasa Indonesia

Mengingat tanggal tanggal, mengembalikan nomor hari (jumlah hari sejak tahun 0). Mengembalikan NULL jika tanggalnya NULL.

Syntax

MYSQL
SELECT TO_DAYS(950501);
728779
SELECT TO_DAYS('2007-10-07');
733321

Contoh

Example

TO_DAYS() is not intended for use with values that precede the advent of the Gregorian calendar (1582), because it does not take into account the days that were lost when the calendar was changed. For dates before 1582 (and possibly a later year in other locales), results from this function are not reliable. See Section 13.2.7, “What Calendar Is Used By MySQL?”, for details.

MYSQL
SELECT TO_DAYS(950501);
728779
SELECT TO_DAYS('2007-10-07');
733321
Example 2

Remember that MySQL converts two-digit year values in dates to four-digit form using the rules in Section 13.2, “Date and Time Data Types”. For example, '2008-10-07' and '08-10-07' are seen as identical dates:

MYSQL
SELECT TO_DAYS('2008-10-07'), TO_DAYS('08-10-07');
733687, 733687
Example 3

In MySQL, the zero date is defined as '0000-00-00', even though this date is itself considered invalid. This means that, for '0000-00-00' and '0000-01-01', TO_DAYS() returns the values shown here:

MYSQL
SELECT TO_DAYS('0000-00-00');
+-----------------------+
| to_days('0000-00-00') |
+-----------------------+
|                  NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)

SHOW WARNINGS;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Incorrect datetime value: '0000-00-00' |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)


SELECT TO_DAYS('0000-01-01');
+-----------------------+
| to_days('0000-01-01') |
+-----------------------+
|                     1 |
+-----------------------+
1 row in set (0.00 sec)