Index: pykota/trunk/pykota/storages/sql.py
===================================================================
--- pykota/trunk/pykota/storages/sql.py (revision 2222)
+++ pykota/trunk/pykota/storages/sql.py (revision 2266)
@@ -124,10 +124,20 @@
     def extractHistory(self, extractonly={}) :
         """Extracts all jobhistory records."""
+        startdate = extractonly.get("start")
+        enddate = extractonly.get("end")
+        for limit in ("start", "end") :
+            try :
+                del extractonly[limit]
+            except KeyError :    
+                pass
         thefilter = self.createFilter(extractonly)
         if thefilter :
             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))
         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)
-        
+            
     def getAllUsersNames(self) :    
         """Extracts all user names."""
@@ -498,6 +508,6 @@
         self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
         
-    def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, billingcode=None, limit=100) :
-        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
+    def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) :
+        """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results."""
         query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid"
         where = []
@@ -510,6 +520,8 @@
         if billingcode is not None :    
             where.append("billingcode=%s" % self.doQuote(self.userCharsetToDatabase(billingcode)))
-        if datelimit is not None :    
-            where.append("jobdate<=%s" % self.doQuote(datelimit))
+        if start is not None :    
+            where.append("jobdate>=%s" % self.doQuote(start))
+        if end is not None :    
+            where.append("jobdate<=%s" % self.doQuote(end))
         if where :    
             query += " AND %s" % " AND ".join(where)
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 2222)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 2266)
@@ -1044,6 +1044,6 @@
             self.doModify(pgroup.ident, fields)         
             
-    def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, billingcode=None, limit=100) :
-        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
+    def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) :
+        """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results."""
         precond = "(objectClass=pykotaJob)"
         where = []
@@ -1110,6 +1110,9 @@
                 minute = int(date[10:12])
                 second = int(date[12:14])
-                job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second)
-                if (datelimit is None) or (job.JobDate <= datelimit) :
+                job.JobDate = "%04i%02i%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second)
+                if ((start is None) and (end is None)) or \
+                   ((start is None) and (job.JobDate <= end)) or \
+                   ((end is None) and (job.JobDate >= start)) or \
+                   ((job.JobDate >= start) and (job.JobDate <= end)) :
                     job.UserName = fields.get("pykotaUserName")[0]
                     job.PrinterName = fields.get("pykotaPrinterName")[0]
@@ -1335,5 +1338,13 @@
         else :    
             printer = None
-        entries = self.retrieveHistory(user, printer, hostname=extractonly.get("hostname"), billingcode=extractonly.get("billingcode"), limit=None)
+        startdate = extractonly.get("start")
+        enddate = extractonly.get("end")
+        for limit in ("start", "end") :
+            try :
+                del extractonly[limit]
+            except KeyError :    
+                pass
+        (startdate, enddate) = self.cleanDates(startdate, enddate)
+        entries = self.retrieveHistory(user, printer, hostname=extractonly.get("hostname"), billingcode=extractonly.get("billingcode"), limit=None, start=startdate, end=enddate)
         if entries :
             result = [ ("username", "printername", "dn", "jobid", "pagecounter", "jobsize", "action", "jobdate", "filename", "title", "copies", "options", "jobprice", "hostname", "jobsizebytes", "md5sum", "pages", "billingcode") ] 
