diff --git a/app/vmstorage/transport/server.go b/app/vmstorage/transport/server.go
index 339b64f0a8..7b3dce96db 100644
--- a/app/vmstorage/transport/server.go
+++ b/app/vmstorage/transport/server.go
@@ -1047,13 +1047,14 @@ func checkTimeRange(s *storage.Storage, tr storage.TimeRange) error {
 	if !*denyQueriesOutsideRetention {
 		return nil
 	}
-	retentionPeriod := s.RetentionMonths()
-	minAllowedTimestamp := (int64(fasttime.UnixTimestamp()) - int64(retentionPeriod)*3600*24*30) * 1000
+	retentionMsecs := s.RetentionMsecs()
+	minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionMsecs
 	if tr.MinTimestamp > minAllowedTimestamp {
 		return nil
 	}
 	return &httpserver.ErrorWithStatusCode{
-		Err:        fmt.Errorf("the given time range %s is outside the allowed retention of %d months according to -denyQueriesOutsideRetention", &tr, retentionPeriod),
+		Err: fmt.Errorf("the given time range %s is outside the allowed retention %.3f days according to -denyQueriesOutsideRetention",
+			&tr, float64(retentionMsecs)/(24*3600*1000)),
 		StatusCode: http.StatusServiceUnavailable,
 	}
 }
diff --git a/lib/storage/storage.go b/lib/storage/storage.go
index 95410313ea..918043c97f 100644
--- a/lib/storage/storage.go
+++ b/lib/storage/storage.go
@@ -50,9 +50,9 @@ type Storage struct {
 	slowPerDayIndexInserts uint64
 	slowMetricNameLoads    uint64
 
-	path            string
-	cachePath       string
-	retentionMonths int
+	path           string
+	cachePath      string
+	retentionMsecs int64
 
 	// lock file for exclusive access to the storage on the given path.
 	flockF *os.File
@@ -129,11 +129,10 @@ func OpenStorage(path string, retentionMsecs int64) (*Storage, error) {
 	if retentionMsecs <= 0 {
 		retentionMsecs = maxRetentionMsecs
 	}
-	retentionMonths := (retentionMsecs + (msecsPerMonth - 1)) / msecsPerMonth
 	s := &Storage{
-		path:            path,
-		cachePath:       path + "/cache",
-		retentionMonths: int(retentionMonths),
+		path:           path,
+		cachePath:      path + "/cache",
+		retentionMsecs: retentionMsecs,
 
 		stop: make(chan struct{}),
 	}
@@ -202,9 +201,9 @@ func OpenStorage(path string, retentionMsecs int64) (*Storage, error) {
 	return s, nil
 }
 
-// RetentionMonths returns retention months for s.
-func (s *Storage) RetentionMonths() int {
-	return s.retentionMonths
+// RetentionMsecs returns retentionMsecs for s.
+func (s *Storage) RetentionMsecs() int64 {
+	return s.retentionMsecs
 }
 
 // debugFlush flushes recently added storage data, so it becomes visible to search.
@@ -488,8 +487,9 @@ func (s *Storage) startRetentionWatcher() {
 }
 
 func (s *Storage) retentionWatcher() {
+	retentionMonths := int((s.retentionMsecs + (msecsPerMonth - 1)) / msecsPerMonth)
 	for {
-		d := nextRetentionDuration(s.retentionMonths)
+		d := nextRetentionDuration(retentionMonths)
 		select {
 		case <-s.stop:
 			return