Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 2657)
+++ /pykota/trunk/pykota/storages/sql.py (revision 2665)
@@ -130,6 +130,8 @@
             thefilter = "AND %s" % thefilter
         (startdate, enddate) = self.cleanDates(startdate, enddate)
-        if startdate and enddate : 
-            thefilter = "%s AND jobdate>=%s AND jobdate<=%s" % (thefilter, self.doQuote(startdate), self.doQuote(enddate))
+        if startdate : 
+            thefilter = "%s AND jobdate>=%s" % (thefilter, self.doQuote(startdate))
+        if enddate : 
+            thefilter = "%s AND jobdate<=%s" % (thefilter, self.doQuote(enddate))
         result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid %s ORDER BY jobhistory.id ASC" % thefilter)
         return self.prepareRawResult(result)
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 2622)
+++ /pykota/trunk/pykota/storage.py (revision 2665)
@@ -679,84 +679,85 @@
     def cleanDates(self, startdate, enddate) :    
         """Clean the dates to create a correct filter."""
-        if startdate is None :
-            startdate = enddate
-        if enddate is None :    
-            enddate = startdate
-        if (startdate is None) and (enddate is None) :    
+        if startdate :    
+            startdate = startdate.strip().lower()
+        if enddate :    
+            enddate = enddate.strip().lower()
+        if (not startdate) and (not enddate) :    
             return (None, None)
             
         now = DateTime.now()    
         nameddates = ('yesterday', 'today', 'now', 'tomorrow')
-        datedict = { "start" : startdate.lower(), "end" : enddate.lower() }    
+        datedict = { "start" : startdate, "end" : enddate }    
         for limit in datedict.keys() :
             dateval = datedict[limit]
-            for name in nameddates :
-                if dateval.startswith(name) :
-                    try :
-                        offset = int(dateval[len(name):])
+            if dateval :
+                for name in nameddates :
+                    if dateval.startswith(name) :
+                        try :
+                            offset = int(dateval[len(name):])
+                        except :    
+                            offset = 0
+                        dateval = dateval[:len(name)]    
+                        if limit == "start" :
+                            if dateval == "yesterday" :
+                                dateval = (now - 1 + offset).Format("%Y%m%d000000")
+                            elif dateval == "today" :
+                                dateval = (now + offset).Format("%Y%m%d000000")
+                            elif dateval == "now" :
+                                dateval = (now + offset).Format("%Y%m%d%H%M%S")
+                            else : # tomorrow
+                                dateval = (now + 1 + offset).Format("%Y%m%d000000")
+                        else :
+                            if dateval == "yesterday" :
+                                dateval = (now - 1 + offset).Format("%Y%m%d235959")
+                            elif dateval == "today" :
+                                dateval = (now + offset).Format("%Y%m%d235959")
+                            elif dateval == "now" :
+                                dateval = (now + offset).Format("%Y%m%d%H%M%S")
+                            else : # tomorrow
+                                dateval = (now + 1 + offset).Format("%Y%m%d235959")
+                        break
+                        
+                if not dateval.isdigit() :
+                    dateval = None
+                else :    
+                    lgdateval = len(dateval)
+                    if lgdateval == 4 :
+                        if limit == "start" : 
+                            dateval = "%s0101 00:00:00" % dateval
+                        else :  
+                            dateval = "%s1231 23:59:59" % dateval
+                    elif lgdateval == 6 :
+                        if limit == "start" : 
+                            dateval = "%s01 00:00:00" % dateval
+                        else :  
+                            mxdate = DateTime.ISO.ParseDateTime("%s01 00:00:00" % dateval)
+                            dateval = "%s%02i 23:59:59" % (dateval, mxdate.days_in_month)
+                    elif lgdateval == 8 :
+                        if limit == "start" : 
+                            dateval = "%s 00:00:00" % dateval
+                        else :  
+                            dateval = "%s 23:59:59" % dateval
+                    elif lgdateval == 10 :
+                        if limit == "start" : 
+                            dateval = "%s %s:00:00" % (dateval[:8], dateval[8:])
+                        else :  
+                            dateval = "%s %s:59:59" % (dateval[:8], dateval[8:])
+                    elif lgdateval == 12 :
+                        if limit == "start" : 
+                            dateval = "%s %s:%s:00" % (dateval[:8], dateval[8:10], dateval[10:])
+                        else :  
+                            dateval = "%s %s:%s:59" % (dateval[:8], dateval[8:10], dateval[10:])
+                    elif lgdateval == 14 :        
+                        dateval = "%s %s:%s:%s" % (dateval[:8], dateval[8:10], dateval[10:12], dateval[12:])
+                    else :    
+                        dateval = None
+                    try :    
+                        DateTime.ISO.ParseDateTime(dateval)
                     except :    
-                        offset = 0
-                    dateval = dateval[:len(name)]    
-                    if limit == "start" :
-                        if dateval == "yesterday" :
-                            dateval = (now - 1 + offset).Format("%Y%m%d000000")
-                        elif dateval == "today" :
-                            dateval = (now + offset).Format("%Y%m%d000000")
-                        elif dateval == "now" :
-                            dateval = (now + offset).Format("%Y%m%d%H%M%S")
-                        else : # tomorrow
-                            dateval = (now + 1 + offset).Format("%Y%m%d000000")
-                    else :
-                        if dateval == "yesterday" :
-                            dateval = (now - 1 + offset).Format("%Y%m%d235959")
-                        elif dateval == "today" :
-                            dateval = (now + offset).Format("%Y%m%d235959")
-                        elif dateval == "now" :
-                            dateval = (now + offset).Format("%Y%m%d%H%M%S")
-                        else : # tomorrow
-                            dateval = (now + 1 + offset).Format("%Y%m%d235959")
-                    break
-                    
-            if not dateval.isdigit() :
-                dateval = None
-            else :    
-                lgdateval = len(dateval)
-                if lgdateval == 4 :
-                    if limit == "start" : 
-                        dateval = "%s0101 00:00:00" % dateval
-                    else :  
-                        dateval = "%s1231 23:59:59" % dateval
-                elif lgdateval == 6 :
-                    if limit == "start" : 
-                        dateval = "%s01 00:00:00" % dateval
-                    else :  
-                        mxdate = DateTime.ISO.ParseDateTime("%s01 00:00:00" % dateval)
-                        dateval = "%s%02i 23:59:59" % (dateval, mxdate.days_in_month)
-                elif lgdateval == 8 :
-                    if limit == "start" : 
-                        dateval = "%s 00:00:00" % dateval
-                    else :  
-                        dateval = "%s 23:59:59" % dateval
-                elif lgdateval == 10 :
-                    if limit == "start" : 
-                        dateval = "%s %s:00:00" % (dateval[:8], dateval[8:])
-                    else :  
-                        dateval = "%s %s:59:59" % (dateval[:8], dateval[8:])
-                elif lgdateval == 12 :
-                    if limit == "start" : 
-                        dateval = "%s %s:%s:00" % (dateval[:8], dateval[8:10], dateval[10:])
-                    else :  
-                        dateval = "%s %s:%s:59" % (dateval[:8], dateval[8:10], dateval[10:])
-                elif lgdateval == 14 :        
-                    dateval = "%s %s:%s:%s" % (dateval[:8], dateval[8:10], dateval[10:12], dateval[12:])
-                else :    
-                    dateval = None
-                try :    
-                    DateTime.ISO.ParseDateTime(dateval)
-                except :    
-                    dateval = None
-            datedict[limit] = dateval    
+                        dateval = None
+                datedict[limit] = dateval    
         (start, end) = (datedict["start"], datedict["end"])
-        if start > end :
+        if start and end and (start > end) :
             (start, end) = (end, start)
         return (start, end)    
