diff --git a/src/@dates/intersect.m b/src/@dates/intersect.m
index 5cbed03fefd3ab3c67a27c5472824e01ca4d64a5..658f4baf2f090db032b25d0ff67694c1a4ad0de5 100644
--- a/src/@dates/intersect.m
+++ b/src/@dates/intersect.m
@@ -38,6 +38,8 @@ if ~isequal(o.freq,p.freq)
     return
 end
 
+% Octave 6.1.0 added support for the 'legacy' option, but we don't use it
+% because of this bug: https://savannah.gnu.org/bugs/?59708
 if isoctave || matlab_ver_less_than('8.1.0')
     time = intersect(o.time,p.time,'rows');
 else
diff --git a/src/@dates/remove_.m b/src/@dates/remove_.m
index 5416231147003604240cf611fb6eb90d530fe078..3ba7efcfa7c463aff0e8cd72a29a5be870a5e136 100644
--- a/src/@dates/remove_.m
+++ b/src/@dates/remove_.m
@@ -42,7 +42,7 @@ if ~isequal(o.freq,p.freq)
     error('dates:remove','Inputs must have common frequency!')
 end
 
-if isoctave || matlab_ver_less_than('8.1.0')
+if (isoctave && octave_ver_less_than('6')) || (~isoctave && matlab_ver_less_than('8.1.0'))
     time = setdiff(o.time,p.time,'rows');
 else
     time = setdiff(o.time,p.time,'rows','legacy');
@@ -140,4 +140,4 @@ o.time = time;
 %$ end
 %$
 %$ T = all(t);
-%@eof:5
\ No newline at end of file
+%@eof:5
diff --git a/src/@dates/setdiff.m b/src/@dates/setdiff.m
index 783cbf9eb9fc8192658112aed8e65e8123819922..55aa91a1f3bda19cf6994978ee18706e26422bf0 100644
--- a/src/@dates/setdiff.m
+++ b/src/@dates/setdiff.m
@@ -48,7 +48,7 @@ if isequal(o.length(),p.length()) && isequal(o, p)
     return
 end
 
-if isoctave || matlab_ver_less_than('8.1.0')
+if (isoctave && octave_ver_less_than('6')) && (~isoctave && matlab_ver_less_than('8.1.0'))
     if nargout<2
         time = setdiff(o.time,p.time,'rows');
     else
diff --git a/src/@dates/unique_.m b/src/@dates/unique_.m
index dd14b4e4fcc9701102187e053062ffb8b2600a25..df0a1216a7438aab5002148326d9ae23a1ae7d29 100644
--- a/src/@dates/unique_.m
+++ b/src/@dates/unique_.m
@@ -30,7 +30,7 @@ if o.ndat()<=1
     return
 end
 
-if isoctave || matlab_ver_less_than('8.1.0')
+if (isoctave && octave_ver_less_than('6')) && (~isoctave && matlab_ver_less_than('8.1.0'))
     [tmp, id, jd] = unique(o.time,'rows');
 else
     [tmp, id, jd] = unique(o.time,'rows','legacy');
@@ -94,4 +94,4 @@ o.time = o.time(sort(id),:);
 %$     t(3) = dassert(d.freq,e.freq);
 %$ end
 %$ T = all(t);
-%@eof:1
\ No newline at end of file
+%@eof:1
diff --git a/src/initialize_dseries_class.m b/src/initialize_dseries_class.m
index 4a276fd7663560a508d626f11ba2e4e152d6ddb4..6ac9e8aaf0b53c111707097a672ebdf68b46e58f 100644
--- a/src/initialize_dseries_class.m
+++ b/src/initialize_dseries_class.m
@@ -50,6 +50,10 @@ if ~exist('matlab_ver_less_than','file')
     p{end+1} = 'utilities/missing/matlab_ver_less_than';
 end
 
+if ~exist('octave_ver_less_than','file')
+    p{end+1} = 'utilities/missing/octave_ver_less_than';
+end
+
 if ~exist('demean','file')
     p{end+1} = 'utilities/missing/demean';
 end
diff --git a/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m b/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m
new file mode 100644
index 0000000000000000000000000000000000000000..0f4fc1fa29900a1fed3671c6d74c2e77d01876ce
--- /dev/null
+++ b/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m
@@ -0,0 +1,37 @@
+function r = octave_ver_less_than(verstr)
+% function r = octave_ver_less_than(verstr)
+%
+% Returns 1 if current Octave version is strictly older than
+% the one given in argument.
+%
+% Note that this function will fail under Matlab.
+%
+% INPUTS
+%    verstr: a string of the format 'x.y' or 'x.y.z'
+%
+% OUTPUTS
+%    r: 0 or 1
+%
+% SPECIAL REQUIREMENTS
+%    none
+
+% Copyright (C) 2008-2019 Dynare Team
+%
+% This file is part of Dynare.
+%
+% Dynare is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% Dynare is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+r = compare_versions(version(), verstr, "<");
+
+endfunction