This might be a little bit unconventional, but if timewrap isn't an option, and if the time periods are consecutive and the searches are the same for both then you could do one search like so. (assuming search-terms are your base search terms and analysis is analysis you do with other functions once you have the results...:
Now this will break if the user selects too large of a time range, and might break on some other edge cases, but what's happening is we have a dummy subsearch to capture the selected timeframe for the overall search using addinfo and with some evals calculate earliest and latest for a search window that's 2x longer (and assuming they "selected" -30d@d to now if they entered all time). Using format, we insert the earliest and latest terms into our main search, where we again use addinfo and an eval to determine if we're on the later selected side or the earlier calculated side.
Now if timeranges aren't consecutive, or searches are different, then it might look something like this (I didn't run this one through a splunk instance... might be a bit more off than above):
An alternative for the subsearch, in case you are intending to compare the previous period with the chosen one, is to use the timewrap command provided by this app: https://splunkbase.splunk.com/app/1645/
I am afraid timewrap is not usefull for me as I need to run a given search for 2 specific time periods picked by the user. The first is the period selected by the time picker and the second is calculated based on that selection (same length previously to the selected range).
I'm looking into something like :
|gentimes start=<earliest - (latest-earliest)> end=<latest> increment=<latest-earliest> | map search=" ......"
The searches should run for the 2 time periods and provide 2 numbers I need to compare.