Welcome @stiosoli to the Grafana forum.
The above is possible, but I only know how to do it using Flux (not InfluxQL). Are you willing to perhaps set up a test system that you could configure with Flux and try it out there? Not sure how many other queries you have built over the past year (and thus how complicated converting everything would be).
Here is how one calculates the number of days selected (it could be hours or seconds or whatever too):