diff --git a/xquery/date.xqm b/xquery/date.xqm
index c6bfe3e07fcfdc34a5db83d9394c57b96dc66201..a06ae59e094b9cdcf899f0c58779b9ab0130a8ba 100755
--- a/xquery/date.xqm
+++ b/xquery/date.xqm
@@ -119,11 +119,11 @@ declare function date:printDate($date as element()?, $lang as xs:string, $get-la
                            else if($date/@to-iso) then date:getCastableDate(data($date/@to-iso),true())
                            else if($date/@when-iso and contains($date/@when-iso, '/')) then date:getCastableDate(data(substring-after($date/@when-iso, '/')),true())                            
                            else()
-        let $from_o-len := if($date/@from-iso) then string-length($date/@from-iso)
-                           else if($date/@when-iso and contains($date/@when-iso, '/')) then string-length(substring-before($date/@when-iso, '/'))
+        let $from_o     := if($date/@from-iso) then string($date/@from-iso)
+                           else if($date/@when-iso and contains($date/@when-iso, '/')) then substring-before($date/@when-iso, '/')
                            else()
-        let $to_o-len    := if($date/@to-iso) then string-length($date/@to-iso)
-                           else if($date/@when-iso and contains($date/@when-iso, '/')) then string-length(substring-after($date/@when-iso, '/'))
+        let $to_o       := if($date/@to-iso) then string($date/@to-iso)
+                           else if($date/@when-iso and contains($date/@when-iso, '/')) then substring-after($date/@when-iso, '/')
                            else()
         
         let $myDate := 
@@ -155,10 +155,10 @@ declare function date:printDate($date as element()?, $lang as xs:string, $get-la
                 if(exists($to)) then 
                     if(year-from-date($from) eq year-from-date($to)) then 
                         if(month-from-date($from) eq month-from-date($to)) then 
-                            if(day-from-date($from) = 1 and day-from-date($to) = functx:days-in-month($to) and $from_o-len lt 9 and $to_o-len lt 9) then date:format-date($from,'[MNn] [Y]', $lang)                (: August 1879 :)
+                            if(day-from-date($from) = 1 and day-from-date($to) = functx:days-in-month($to) and $from_o castable as xs:gYearMonth) then date:format-date($from,'[MNn] [Y]', $lang)                (: August 1879 :)
                             else $get-language-string('fromTo',(xs:string(day-from-date($from)),date:format-date($to,$picture-string, $lang)))                       (: Vom 1. bis 7. August 1801 :)
                         else if(ends-with($from, '01-01') and ends-with($to, '12-31')) then date:formatYear(year-from-date($from), $lang)                                            (: 1879 :)
-                        else if($from_o-len lt 9 and $to_o-len lt 9) then $get-language-string('noFromTo',(date:format-date($from,'[MNn]', $lang),date:format-date($to,'[MNn] [Y]', $lang))) (: Mai bis August 1909 :)
+                        else if($from_o castable as xs:gYearMonth and $to_o castable as xs:gYearMonth) then $get-language-string('noFromTo',(date:format-date($from,'[MNn]', $lang),date:format-date($to,'[MNn] [Y]', $lang))) (: Mai bis August 1909 :)
                         else $get-language-string('fromTo', (replace(date:format-date($from,$picture-string, $lang), '(,\s+)?' || date:formatYear(year-from-date($from), $lang), ''), date:format-date($to,$picture-string, $lang))) (: Vom 1. Juli bis 4. August 1789 :)
                     else $get-language-string('fromTo', (date:format-date($from,$picture-string, $lang), date:format-date($to,$picture-string, $lang)))                     (: Vom 1. Juli 1709 bis 4. August 1789 :)
                 else $get-language-string('fromToUnknown', date:format-date($from,$picture-string, $lang))    (: Vom 1.Juli 1709 bis unbekannt :)