diff --git a/src/mtime_timedelta.c b/src/mtime_timedelta.c
index 4ccbfa5086fd4b5f9cc2e3011e3ba4f7fad5d383..1adc9cfc46d739cf869f26cbc1c43b2246537bdd 100644
--- a/src/mtime_timedelta.c
+++ b/src/mtime_timedelta.c
@@ -1213,7 +1213,7 @@ divideTimeDelta(struct _timedelta* dividend, struct _timedelta* divisor,
   quo_ret->quotient        = (int64_t) 0;
   quo_ret->remainder_days  = (int64_t) 0;
   quo_ret->remainder_in_ms = (int64_t) 0;
-  if (ret != 0) {
+  if (ret == 0) {
     quo_ret->quotient        = (int64_t) q_decimal;
     quo_ret->remainder_days  = (int64_t) remainder_days;
     quo_ret->remainder_in_ms = (int64_t) remainder_ms;
@@ -1231,7 +1231,7 @@ divideTimeDelta(struct _timedelta* dividend, struct _timedelta* divisor,
   deallocateJulianDelta(jd_dividend);
   deallocateJulianDelta(jd_divisor);
 
-  if (ret == 0)  return NULL;
+  if (ret != 0)  return NULL;
 
   return (quo_ret);
 }