diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index 85ba5d7..9f2b69c 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -2778,5 +2778,73 @@ Warning	1292	Truncated incorrect time value: '-1441:00:00'
 Warning	1292	Truncated incorrect time value: '-1441:00:00'
 Warning	1292	Truncated incorrect time value: '-1441:00:00'
 #
+# MDEV-10787 Assertion `ltime->neg == 0' failed in void date_to_datetime(MYSQL_TIME*)
+#
+CREATE TABLE t1 (d DATE);
+INSERT INTO t1 VALUES ('2005-07-20'),('2012-12-21');
+SELECT REPLACE( ADDDATE( d, INTERVAL 0.6732771076944444 HOUR_SECOND ), '2', 'x' ) FROM t1;
+REPLACE( ADDDATE( d, INTERVAL 0.6732771076944444 HOUR_SECOND ), '2', 'x' )
+NULL
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+Warning	1441	Datetime function: datetime field overflow
+SELECT REPLACE( ADDDATE( d, INTERVAL '0.6732771076944444' HOUR_SECOND ), '2', 'x' ) FROM t1;
+REPLACE( ADDDATE( d, INTERVAL '0.6732771076944444' HOUR_SECOND ), '2', 'x' )
+NULL
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+Warning	1441	Datetime function: datetime field overflow
+SELECT CAST(ADDDATE( d, INTERVAL 6732771076944444 SECOND) AS CHAR) FROM t1;
+CAST(ADDDATE( d, INTERVAL 6732771076944444 SECOND) AS CHAR)
+NULL
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+Warning	1441	Datetime function: datetime field overflow
+SELECT CAST(ADDDATE( d, INTERVAL '67327710769444:44' HOUR_SECOND) AS CHAR) FROM t1;
+CAST(ADDDATE( d, INTERVAL '67327710769444:44' HOUR_SECOND) AS CHAR)
+NULL
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+Warning	1441	Datetime function: datetime field overflow
+SELECT CAST(ADDDATE( d, INTERVAL '673277107694:44:44' HOUR_SECOND) AS CHAR) FROM t1;
+CAST(ADDDATE( d, INTERVAL '673277107694:44:44' HOUR_SECOND) AS CHAR)
+NULL
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+Warning	1441	Datetime function: datetime field overflow
+DROP TABLE t1;
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:23:59:59' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '3652423:23:59:59' DAY_SECOND)
+9999-12-31 23:59:59
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:59:59' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:59:59' DAY_SECOND)
+9999-12-31 23:59:59
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:59' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:59' DAY_SECOND)
+9999-12-31 23:59:59
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:0:315569433559' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '0:0:0:315569433559' DAY_SECOND)
+9999-12-31 23:59:19
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:0:0:315569433559' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '3652423:0:0:315569433559' DAY_SECOND)
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:0:315569433559' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:0:315569433559' DAY_SECOND)
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:315569433559' DAY_SECOND);
+ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:315569433559' DAY_SECOND)
+NULL
+Warnings:
+Warning	1441	Datetime function: datetime field overflow
+#
 # End of 10.0 tests
 #
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index f2c53bd..92a776b 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -1705,6 +1705,31 @@ SELECT
   TIMEDIFF(20140101000000.000    , 20140302010000.000    ) AS dec_dec,
   TIMEDIFF(20140101000000.000    , '2014-03-02 01:00:00' ) AS dec_str;
 
+
+--echo #
+--echo # MDEV-10787 Assertion `ltime->neg == 0' failed in void date_to_datetime(MYSQL_TIME*)
+--echo #
+CREATE TABLE t1 (d DATE);
+INSERT INTO t1 VALUES ('2005-07-20'),('2012-12-21');
+SELECT REPLACE( ADDDATE( d, INTERVAL 0.6732771076944444 HOUR_SECOND ), '2', 'x' ) FROM t1;
+SELECT REPLACE( ADDDATE( d, INTERVAL '0.6732771076944444' HOUR_SECOND ), '2', 'x' ) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL 6732771076944444 SECOND) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL '67327710769444:44' HOUR_SECOND) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL '673277107694:44:44' HOUR_SECOND) AS CHAR) FROM t1;
+DROP TABLE t1;
+
+# Maximum possible DAY_SECOND values in various formats
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:23:59:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:59:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:0:315569433559' DAY_SECOND);
+
+# Out-of-range INTERVAL DAY_SECOND values
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:0:0:315569433559' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:0:315569433559' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:315569433559' DAY_SECOND);
+
+
 --echo #
 --echo # End of 10.0 tests
 --echo #
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index b55b1d7..1bd68e8 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -930,7 +930,10 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
     my_bool neg= 0;
     enum enum_mysql_timestamp_type time_type= ltime->time_type;
 
-    if ((ulong) interval.day > MAX_DAY_NUMBER)
+    if (((ulonglong) interval.day +
+         (ulonglong) interval.hour / 24 +
+         (ulonglong) interval.minute / 24 / 60 +
+         (ulonglong) interval.second / 24 / 60 / 60) > MAX_DAY_NUMBER)
       goto invalid_date;
 
     if (time_type != MYSQL_TIMESTAMP_TIME)
