You can access variables from a text panel for example. Built-in variables may help you? There are an open feature request that you may upvote if interested. Otherwise I guess you have to build your own plugin.
You can fetch the current timeRange values from the DOM by using (the already available) angular.
<script type="text/javascript">
var timeRange = angular.element('grafana-app').injector().get('timeSrv').timeRange();
var temp_date_from = new Date(timeRange.from);
var temp_date_to = new Date(timeRange.to);
// Do what you want with the data
</script>