def GetCurrentMicroSeconds(dt=None): # Ensure the type matches if not dt: dt = datetime.datetime.now() elif type(dt) == type(datetime.datetime.now()): return time.mktime(dt.timetuple())+float("0.%s"%dt.microsecond) elif type(dt) == type(datetime.date.today()): return time.mktime(dt.timetuple()) else: raise ValueError, "You may only use a datetime.datetime or datetime.date instance with GetCurrentMicroSeconds" """ Basic Usage """ import datetime # create two example dates t = datetime.date.today() ts = datetime.datetime.now() # returns something like 1272322800.0 GetCurrentMicroSeconds(t) # returns something like 1272366481.381309 GetCurrentMicroSeconds(ts) """ Example Django Usage: """ class TestObject: date_created = models.FloatField(default=time.time, editable=False, blank=False, null=False) # Determine the current day, month and year. today = datetime.date.today() # Determine first day of month first_day = datetime.date(today.year, today.month, 1) # Determine last day of month last_day = last_day_of_month(today.year, today.month) result = TestObject.objects.filter( date_created__gte = GetCurrentMicroSeconds(first_day), date_created__lte = GetCurrentMicroSeconds(last_day) )