<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Nora Mullen</title>
    <description>Posts by Nora Mullen on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/nora-mullen/</link>
    <language>en-us</language>
    <lastBuildDate>Fri, 26 Jun 2020 07:00:35 -0700</lastBuildDate>
    <pubDate>Fri, 26 Jun 2020 07:00:35 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>TL;DR Tech Tips — Flux Time Ranges</title>
      <description>&lt;p&gt;In this post, we share some basics about working with time ranges in Flux.&lt;/p&gt;
&lt;h3&gt;Q: What's the role of time ranges in Flux queries?&lt;/h3&gt;
&lt;p&gt;A: Flux requires a time range when querying InfluxDB. “Unbounded” queries are very resource-intensive and as a protective measure, Flux won’t query InfluxDB without a specified range.&lt;/p&gt;

&lt;p&gt;After you use the &lt;code class="language-javascript"&gt;from()&lt;/code&gt; function to define a data source, use the pipe-forward operator (&lt;code class="language-javascript"&gt;|&amp;gt;&lt;/code&gt;) to pipe data from your data source into the &lt;code class="language-javascript"&gt;range()&lt;/code&gt; function. (We’ll dive into specific examples below.)&lt;/p&gt;
&lt;h3&gt;Q: What parameters does the range() function have?&lt;/h3&gt;
&lt;p&gt;A: The &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/built-in/transformations/range/"&gt;&lt;code class="language-javascript"&gt;range()&lt;/code&gt; function&lt;/a&gt; has two parameters: &lt;code class="language-javascript"&gt;start&lt;/code&gt;, the earliest time to include in results, and &lt;code class="language-javascript"&gt;stop&lt;/code&gt;. For each parameter, define either a &lt;strong&gt;relative &lt;/strong&gt;or &lt;strong&gt;absolute &lt;/strong&gt;time. Learn more about each option below.&lt;/p&gt;
&lt;h3&gt;Q: How do you set a relative time range in Flux?&lt;/h3&gt;
&lt;p&gt;A: Define a &lt;strong&gt;relative&lt;/strong&gt; range for your Flux query using durations relative to &lt;code class="language-javascript"&gt;now()&lt;/code&gt;. Durations are formatted as &lt;em&gt;&lt;a href="https://v2.docs.influxdata.com/v2.0/reference/flux/language/lexical-elements/#duration-literals"&gt;duration literals&lt;/a&gt;&lt;/em&gt;, representations of a length of time with an integer part and a duration unit part: for example, &lt;code class="language-javascript"&gt;-1h&lt;/code&gt; represents a time range of one hour before now.&lt;/p&gt;
&lt;h4&gt;Example relative time range in a Flux query&lt;/h4&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;// Relative time range with start only. Stop defaults to now.
from(bucket:"example-bucket")
  |&amp;gt; range(start: -1h)
  // ...

// Relative time range with start and stop
from(bucket:"example-bucket")
  |&amp;gt; range(start: -1h, stop: -10m)
  // ...&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Q: How do you set an absolute time range in Flux?&lt;/h3&gt;
&lt;p&gt;A: Define an &lt;strong&gt;absolute &lt;/strong&gt;range for your Flux query using timestamps. Timestamps are formatted as &lt;em&gt;&lt;a href="https://v2.docs.influxdata.com/v2.0/reference/flux/language/lexical-elements/#date-and-time-literals"&gt;date and time literals&lt;/a&gt;&lt;/em&gt;, composed of a date part, a time part, and an optional time offset par: for example, &lt;code class="language-javascript"&gt;2019-10-15T09:00:00&lt;/code&gt; represents October 15, 2019.&lt;/p&gt;
&lt;h4&gt;Example absolute time range&lt;/h4&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;from(bucket:"example-bucket")
  |&amp;gt; range(start: 2019-11-05T23:30:00Z, stop: 2019-11-06T00:00:00Z)
  // ...&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Q: Does the &lt;code class="language-javascript"&gt;range()&lt;/code&gt; function include points that match the start or stop time?&lt;/h3&gt;
&lt;p&gt;A: For the &lt;code class="language-javascript"&gt;start&lt;/code&gt; parameter, results &lt;strong&gt;include &lt;/strong&gt;points that match the specified start time. For the stop parameter, results &lt;strong&gt;exclude &lt;/strong&gt;points that match the specified end time.&lt;/p&gt;

&lt;p&gt;In the following example, points matching &lt;code class="language-javascript"&gt;-12h&lt;/code&gt; would be included and points matching &lt;code class="language-javascript"&gt;-15m&lt;/code&gt; would be excluded.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;from(bucket:"example-bucket")
  |&amp;gt; range(start:-12h, stop: -15m)
  // ...&lt;/code&gt;&lt;/pre&gt;
</description>
      <pubDate>Fri, 26 Jun 2020 07:00:35 -0700</pubDate>
      <link>https://www.influxdata.com/blog/tldr-tech-tips-flux-time-ranges/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/tldr-tech-tips-flux-time-ranges/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Nora Mullen (InfluxData)</author>
    </item>
    <item>
      <title>TL;DR InfluxDB Tech Tips – Flux Timestamps</title>
      <description>&lt;p&gt;In this post, we share some quick examples of how you can work with timestamps in Flux.&lt;/p&gt;
&lt;h3&gt;Q: What timestamp formats are available in Flux?&lt;/h3&gt;
&lt;p&gt;A: There are two timestamp formats available:&lt;/p&gt;
&lt;h4&gt;Unix timestamp&lt;/h4&gt;
&lt;p&gt;A Unix timestamp counts time since Unix Epoch (1970-01-01T00:00:00Z UTC) in specified units. The units are determined by the &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/glossary/#precision"&gt;precision&lt;/a&gt; you set when writing data to InfluxDB.&lt;/p&gt;

&lt;p&gt;InfluxDB supports the following Unix timestamp precisions:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align="left"&gt;Precision&lt;/th&gt;
&lt;th align="left"&gt;Description&lt;/th&gt;
&lt;th align="left"&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;ns&lt;/code&gt;&lt;/td&gt;
&lt;td align="left"&gt;Nanoseconds&lt;/td&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;1577836800000000000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;us&lt;/code&gt;&lt;/td&gt;
&lt;td align="left"&gt;Microseconds&lt;/td&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;1577836800000000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;ms&lt;/code&gt;&lt;/td&gt;
&lt;td align="left"&gt;Milliseconds&lt;/td&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;1577836800000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;s&lt;/code&gt;&lt;/td&gt;
&lt;td align="left"&gt;Seconds&lt;/td&gt;
&lt;td align="left"&gt;&lt;code class="language-javascript"&gt;1577836800&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;The examples above represent &lt;strong&gt;2020-01-01T00:00:00Z UTC&lt;/strong&gt;. &lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;RFC3339 timestamp&lt;/h4&gt;
&lt;p&gt;An RFC3339 timestamp that uses the human readable DateTime format proposed in RFC 3339 (for example: 2020-01-01T00:00:00.00Z). Flux and InfluxDB clients return query results with RFC3339 timestamps.&lt;/p&gt;
&lt;h3&gt;Q: How do I convert the timestamp format?&lt;/h3&gt;
&lt;p&gt;A: To convert timestamps from Unix nanoseconds to a human readable RFC3339 timestamp, use the &lt;code class="language-javascript"&gt;time()&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;time(v: 1568808000000000000)
// Returns 2019-09-18T12:00:00.000000000Z&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To convert timestamps from RFC3339 to Unix nanoseconds, use the &lt;code class="language-javascript"&gt;uint()&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;uint(v: 2019-09-18T12:00:00.000000000Z)
// Returns 1568808000000000000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Q: How do I calculate the duration between two timestamps?&lt;/p&gt;

&lt;p&gt;A: Flux doesn’t support mathematical operations using time type values. To calculate the duration between two timestamps:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li&gt;Use the uint() function to convert each timestamp to a Unix nanosecond timestamp.&lt;/li&gt;
 	&lt;li&gt;Subtract one Unix nanosecond timestamp from the other.&lt;/li&gt;
 	&lt;li&gt;Use the duration() function to convert the result into a duration.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;time1 = uint(v: 2019-09-17T21:12:05Z)
time2 = uint(v: 2019-09-18T22:16:35Z)

duration(v: time2 - time1)
// Returns 25h4m30s&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Q: How do I retrieve the current time?&lt;/h3&gt;
&lt;p&gt;A: To retrieve the current time in UTC, use the &lt;code class="language-javascript"&gt;now()&lt;/code&gt; function. Note that the &lt;code class="language-javascript"&gt;now()&lt;/code&gt; function is cached at runtime, so all instances of &lt;code class="language-javascript"&gt;now()&lt;/code&gt; return the same value.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;now()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To retrieve the current system time of the host machine in RFC3339 format, import the system package and the &lt;code class="language-javascript"&gt;system.time()&lt;/code&gt; function:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;import "system"

system.time()&lt;/code&gt;&lt;/pre&gt;
</description>
      <pubDate>Thu, 11 Jun 2020 07:00:10 -0700</pubDate>
      <link>https://www.influxdata.com/blog/tldr-tech-tips-flux-timestamps/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/tldr-tech-tips-flux-timestamps/</guid>
      <category>Use Cases</category>
      <category>Developer</category>
      <category>Product</category>
      <author>Nora Mullen (InfluxData)</author>
    </item>
  </channel>
</rss>
