<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  $dateAdd (aggregation)
  <a class="headerlink leafygreen-ui-1kepx47" href="#-dateadd--aggregation-" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="-dateadd--aggregation-">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
     <span>
      Definition
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
     <span>
      Behavior
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
     <span>
      Examples
     </span>
    </a>
   </li>
  </ul>
 </div>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Definition
   <a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="definition">
    </div>
   </a>
  </h2>
  <dl class="expression">
   <dt>
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-dateAdd" title="Permalink to this definition">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-dateAdd">
     </div>
    </a>
   </dt>
   <dd>
    <div>
     <p>
      <em>
       New
       <!-- -->
       in version
       <!-- -->
       5.0
      </em>
      .
     </p>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Increments a
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Date/#mongodb-method-Date">
      <code class="leafygreen-ui-1l06pbn">
       Date()
      </code>
     </a>
     object by a
specified number of time units.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateAdd" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        $dateAdd
       </code>
      </span>
     </a>
     expression has the following syntax:
    </p>
    <script class="structured_data" type="application/ld+json">
     {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   $dateAdd: {\n      startDate: &lt;expression&gt;,\n      unit: &lt;expression&gt;,\n      amount: &lt;expression&gt;,\n      timezone: &lt;tzexpression&gt;\n   }\n}","programmingLanguage":"JavaScript"}
    </script>
    <div class="css-16lmvu9">
     <div class="leafygreen-ui-196mwvg">
      <div class="leafygreen-ui-yzcs8i">
       <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-attr">$dateAdd</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">startDate</span>: &lt;<span class="lg-highlight-title lg-highlight-class">Expression</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">unit</span>: &lt;<span class="lg-highlight-title lg-highlight-class">Expression</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">amount</span>: &lt;<span class="lg-highlight-title lg-highlight-class">Expression</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">timezone</span>: &lt;<!-- -->tzExpression<!-- -->&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
       <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
        <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
         <div class="leafygreen-ui-xhlipt">
          <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
           <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
           </path>
          </svg>
         </div>
        </button>
       </div>
      </div>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Returns a
     <code class="leafygreen-ui-1l06pbn">
      Date()
     </code>
     . The
     <code class="leafygreen-ui-1l06pbn">
      startDate
     </code>
     can be any expression that
resolves to type Date, Timestamp or ObjectId. No matter which data
type is used as input, the value returned will be a
     <code class="leafygreen-ui-1l06pbn">
      Date()
     </code>
     object.
    </p>
    <div class="leafygreen-ui-skkc39" tabindex="0">
     <table class="leafygreen-ui-hr8lsv">
      <colgroup>
       <col style="width:20%"/>
       <col style="width:20%"/>
       <col style="width:60%"/>
      </colgroup>
      <thead class="leafygreen-ui-a9ho40">
       <tr data-testid="leafygreen-ui-header-row">
        <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Field
          </div>
         </div>
        </th>
        <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Required/Optional
          </div>
         </div>
        </th>
        <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Description
          </div>
         </div>
        </th>
       </tr>
      </thead>
      <tbody>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            startDate
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           Required
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           The beginning date, in UTC, for the addition operation. The
           <code class="leafygreen-ui-1l06pbn">
            startDate
           </code>
           can be any
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
            expression
           </a>
           that resolves to
a
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-date">
            Date
           </a>
           , a
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp">
            Timestamp
           </a>
           ,
or an
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-object-id">
            ObjectID
            <!-- -->
            .
           </a>
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            unit
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           Required
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <p class="leafygreen-ui-1kp3ins">
            The
            <code class="leafygreen-ui-1l06pbn">
             unit
            </code>
            used to measure the
            <code class="leafygreen-ui-1l06pbn">
             amount
            </code>
            of time added to
the
            <code class="leafygreen-ui-1l06pbn">
             startDate
            </code>
            . The
            <code class="leafygreen-ui-1l06pbn">
             unit
            </code>
            is an
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
             expression
            </a>
            that resolves to
one of the following strings:
           </p>
           <ul class="leafygreen-ui-rioki0">
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               year
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               quarter
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               week
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               month
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               day
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               hour
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               minute
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               second
              </code>
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              <code class="leafygreen-ui-1l06pbn">
               millisecond
              </code>
             </p>
            </li>
           </ul>
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            amount
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           Required
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           The number of
           <code class="leafygreen-ui-1l06pbn">
            units
           </code>
           added to the
           <code class="leafygreen-ui-1l06pbn">
            startDate
           </code>
           . The
           <code class="leafygreen-ui-1l06pbn">
            amount
           </code>
           is an
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
            expression
           </a>
           that resolves to an integer or long. The
           <code class="leafygreen-ui-1l06pbn">
            amount
           </code>
           can also
resolve to an integral decimal or a double if that value can
be converted to a long without loss of precision.
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            timezone
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           Optional
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <p class="leafygreen-ui-1kp3ins">
            The timezone to carry out the operation.
            <code class="leafygreen-ui-1l06pbn">
             &lt;tzExpression&gt;
            </code>
            must be a
valid
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
             expression
            </a>
            that resolves to a
string formatted as either an
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" rel="noopener noreferrer">
             <span>
              Olson Timezone Identifier
             </span>
             <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
              <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
              </path>
              <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
              </path>
             </svg>
            </a>
            or a
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/List_of_UTC_time_offsets" rel="noopener noreferrer">
             <span>
              UTC Offset
             </span>
             <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
              <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
              </path>
              <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
              </path>
             </svg>
            </a>
            .
If no
            <code class="leafygreen-ui-1l06pbn">
             timezone
            </code>
            is provided, the result is displayed in
            <code class="leafygreen-ui-1l06pbn">
             UTC
            </code>
            .
           </p>
           <div class="leafygreen-ui-skkc39" tabindex="0">
            <table class="leafygreen-ui-hr8lsv">
             <colgroup>
              <col style="width:30%"/>
              <col style="width:70%"/>
             </colgroup>
             <thead class="leafygreen-ui-a9ho40">
              <tr data-testid="leafygreen-ui-header-row">
               <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
                <div class="leafygreen-ui-ui0te9">
                 <div>
                  Format
                 </div>
                </div>
               </th>
               <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
                <div class="leafygreen-ui-ui0te9">
                 <div>
                  Examples
                 </div>
                </div>
               </th>
              </tr>
             </thead>
             <tbody>
              <tr class="">
               <td class="leafygreen-ui-1drjk7h">
                <div class="leafygreen-ui-1n4j8xf">
                 <div>
                  Olson Timezone Identifier
                 </div>
                </div>
               </td>
               <td class="leafygreen-ui-1drjk7h">
                <div class="leafygreen-ui-1n4j8xf">
                 <div>
                  <script class="structured_data" type="application/ld+json">
                   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"America/New_York\"\n\"Europe/London\"\n\"GMT\"","programmingLanguage":"Bash"}
                  </script>
                  <div class="css-16lmvu9">
                   <div class="leafygreen-ui-196mwvg">
                    <div class="leafygreen-ui-1b1bvay">
                     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"America/New_York"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"Europe/London"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"GMT"</span></td></tr></tbody></table></code></pre>
                     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
                      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
                       <div class="leafygreen-ui-xhlipt">
                        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
                         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
                         </path>
                        </svg>
                       </div>
                      </button>
                     </div>
                    </div>
                   </div>
                  </div>
                 </div>
                </div>
               </td>
              </tr>
              <tr class="">
               <td class="leafygreen-ui-1drjk7h">
                <div class="leafygreen-ui-1n4j8xf">
                 <div>
                  UTC Offset
                 </div>
                </div>
               </td>
               <td class="leafygreen-ui-1drjk7h">
                <div class="leafygreen-ui-1n4j8xf">
                 <div>
                  <script class="structured_data" type="application/ld+json">
                   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"+/-[hh]:[mm], e.g. \"+04:45\"\n+/-[hh][mm], e.g. \"-0530\"\n+/-[hh], e.g. \"+03\"","programmingLanguage":"Bash"}
                  </script>
                  <div class="css-16lmvu9">
                   <div class="leafygreen-ui-196mwvg">
                    <div class="leafygreen-ui-1b1bvay">
                     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">+<!-- -->/-<!-- -->[hh]:[mm], e.g. <span class="lg-highlight-string">"+04:45"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">+<!-- -->/-<!-- -->[hh][mm], e.g. <span class="lg-highlight-string">"-0530"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">+<!-- -->/-<!-- -->[hh], e.g. <span class="lg-highlight-string">"+03"</span></td></tr></tbody></table></code></pre>
                     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
                      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
                       <div class="leafygreen-ui-xhlipt">
                        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
                         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
                         </path>
                        </svg>
                       </div>
                      </button>
                     </div>
                    </div>
                   </div>
                  </div>
                 </div>
                </div>
               </td>
              </tr>
             </tbody>
            </table>
           </div>
          </div>
         </div>
        </td>
       </tr>
      </tbody>
     </table>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     For more information on expressions and types see
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
      Expression Operators
     </a>
     and
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
      BSON Types
      <!-- -->
      .
     </a>
    </p>
   </dd>
  </dl>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Behavior
   <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="behavior">
    </div>
   </a>
  </h2>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Time Measurement
    <a class="headerlink leafygreen-ui-1kepx47" href="#time-measurement" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="time-measurement">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    MongoDB follows prevaling database usage and works with time in UTC. The
    <code class="leafygreen-ui-1l06pbn">
     dateAdd
    </code>
    expression always takes a
    <code class="leafygreen-ui-1l06pbn">
     startDate
    </code>
    in UTC and returns
a result in UTC. If the
    <code class="leafygreen-ui-1l06pbn">
     timezone
    </code>
    is specified, the calculation will
be done using the specified
    <code class="leafygreen-ui-1l06pbn">
     timezone
    </code>
    . The timezone is especially
important when a calculation involves Daylight Savings Time (DST).
   </p>
   <p class="leafygreen-ui-1kp3ins">
    If the
    <code class="leafygreen-ui-1l06pbn">
     unit
    </code>
    is a
    <code class="leafygreen-ui-1l06pbn">
     month
    </code>
    , or larger the operation adjusts to
account for the last day of the month. Adding one
    <code class="leafygreen-ui-1l06pbn">
     month
    </code>
    on the last
day of October, for example, demonstrates the "last-day-of-the-month"
adjustment.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   $dateAdd:\n      {\n         startDate: ISODate(\"2020-10-31T12:10:05Z\"),\n         unit: \"month\",\n         amount: 1\n      }\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-10-31T12:10:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"month"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    Notice that the date returned,
    <code class="leafygreen-ui-1l06pbn">
     ISODate("2020-11-30T12:10:05Z")
    </code>
    , is
the 30th and not the 31st since November has fewer days than October.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Time Zone
    <a class="headerlink leafygreen-ui-1kepx47" href="#time-zone" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="time-zone">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    When using an Olson Timezone Identifier in the
    <code class="leafygreen-ui-1l06pbn">
     &lt;timezone&gt;
    </code>
    field, MongoDB applies the
    <span class="leafygreen-ui-vm4wms" tabindex="0">
     DST
    </span>
    offset
if applicable for the specified timezone.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For example, consider a
    <code class="leafygreen-ui-1l06pbn">
     sales
    </code>
    collection with the following document:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   \"_id\" : 1,\n   \"item\" : \"abc\",\n   \"price\" : 20,\n   \"quantity\" : 5,\n   \"date\" : ISODate(\"2017-05-20T10:24:51.303Z\")\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">20</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-05-20T10:24:51.303Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The following aggregation illustrates how MongoDB handles the DST
offset for the Olson Timezone Identifier. The example uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/hour/#mongodb-expression-exp.-hour">
     <code class="leafygreen-ui-1l06pbn">
      $hour
     </code>
    </a>
    and
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/minute/#mongodb-expression-exp.-minute">
     <code class="leafygreen-ui-1l06pbn">
      $minute
     </code>
    </a>
    operators to return the
corresponding portions of the
    <code class="leafygreen-ui-1l06pbn">
     date
    </code>
    field:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate([\n{\n   $project: {\n      \"nycHour\": {\n         $hour: { date: \"$date\", timezone: \"-05:00\" }\n       },\n       \"nycMinute\": {\n          $minute: { date: \"$date\", timezone: \"-05:00\" }\n       },\n       \"gmtHour\": {\n          $hour: { date: \"$date\", timezone: \"GMT\" }\n       },\n       \"gmtMinute\": {\n          $minute: { date: \"$date\", timezone: \"GMT\" } },\n       \"nycOlsonHour\": {\n          $hour: { date: \"$date\", timezone: \"America/New_York\" }\n       },\n       \"nycOlsonMinute\": {\n          $minute: { date: \"$date\", timezone: \"America/New_York\" }\n       }\n   }\n}])","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"nycHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-05:00"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"nycMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-05:00"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"gmtHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"GMT"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"gmtMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"GMT"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"nycOlsonHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"nycOlsonMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}])</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The operation returns the following result:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   \"_id\": 1,\n   \"nycHour\" : 5,\n   \"nycMinute\" : 24,\n   \"gmtHour\" : 10,\n   \"gmtMinute\" : 24,\n   \"nycOlsonHour\" : 6,\n   \"nycOlsonMinute\" : 24\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"nycHour"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"nycMinute"</span> <!-- -->: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"gmtHour"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"gmtMinute"</span> <!-- -->: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"nycOlsonHour"</span> <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"nycOlsonMinute"</span> <!-- -->: <span class="lg-highlight-number">24</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Examples
   <a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="examples">
    </div>
   </a>
  </h2>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Add a Future Date
    <a class="headerlink leafygreen-ui-1kepx47" href="#add-a-future-date" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="add-a-future-date">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Consider a collection of customer orders with these documents:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.insertMany(\n  [\n     { custId: 456, purchaseDate: ISODate(\"2020-12-31\") },\n     { custId: 457, purchaseDate: ISODate(\"2021-02-28\") },\n     { custId: 458, purchaseDate: ISODate(\"2021-02-26\") }\n  ]\n)","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">456</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-12-31"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">457</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-28"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">458</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-26"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The normal shipping time is 3 days. You can use
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    in an
aggregation pipeline to set an
    <code class="leafygreen-ui-1l06pbn">
     expectedDeliveryDate
    </code>
    3 days in the
future.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.aggregate(\n   [\n      {\n         $project:\n            {\n               expectedDeliveryDate:\n                  {\n                     $dateAdd:\n                        {\n                           startDate: \"$purchaseDate\",\n                           unit: \"day\",\n                           amount: 3\n                        }\n                  }\n            }\n       },\n       {\n          $merge: \"shipping\"\n       }\n    ]\n )","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">expectedDeliveryDate</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$purchaseDate"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$merge</span>: <span class="lg-highlight-string">"shipping"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    After adding 3 days to the
    <code class="leafygreen-ui-1l06pbn">
     purchaseDate
    </code>
    with
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    in the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
     <code class="leafygreen-ui-1l06pbn">
      $project
     </code>
    </a>
    stage, the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
     <code class="leafygreen-ui-1l06pbn">
      $merge
     </code>
    </a>
    stage updates the
original documents with the
    <code class="leafygreen-ui-1l06pbn">
     expectedDeliveryDate
    </code>
    .
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The resulting documents look like this:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   \"_id\" : ObjectId(\"603dd4b2044b995ad331c0b2\"),\n   \"custId\" : 456,\n   \"purchaseDate\" : ISODate(\"2020-12-31T00:00:00Z\"),\n   \"expectedDeliveryDate\" : ISODate(\"2021-01-03T00:00:00Z\")\n}\n{\n   \"_id\" : ObjectId(\"603dd4b2044b995ad331c0b3\"),\n   \"custId\" : 457,\n   \"purchaseDate\" : ISODate(\"2021-02-28T00:00:00Z\"),\n   \"expectedDeliveryDate\" : ISODate(\"2021-03-03T00:00:00Z\")\n}\n{\n    \"_id\" : ObjectId(\"603dd4b2044b995ad331c0b4\"),\n   \"custId\" : 458,\n   \"purchaseDate\" : ISODate(\"2021-02-26T00:00:00Z\"),\n   \"expectedDeliveryDate\" : ISODate(\"2021-03-01T00:00:00Z\")\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1jheeh3">
      <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b2"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">456</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-12-31T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-01-03T00:00:00Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">457</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-28T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-03T00:00:00Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b4"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">458</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-26T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-01T00:00:00Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Filter on a Date Range
    <a class="headerlink leafygreen-ui-1kepx47" href="#filter-on-a-date-range" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="filter-on-a-date-range">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Update the
    <code class="leafygreen-ui-1l06pbn">
     shipping
    </code>
    collection from the last example with this code
to add delivery dates to the documents:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.updateOne(\n   { custId: 456 },\n   { $set: { deliveryDate: ISODate( \"2021-01-10\" ) } }\n)\n\ndb.shipping.updateOne(\n  { custId: 457 },\n  { $set: { deliveryDate:  ISODate( \"2021-03-01\" ) } }\n)\n\ndb.shipping.updateOne(\n   { custId: 458 },\n   { $set: { deliveryDate:  ISODate( \"2021-03-02\" ) } }\n)","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">456</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-01-10"</span> ) } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">457</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>:  <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-01"</span> ) } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">458</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>:  <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-02"</span> ) } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    You want to find late shipments. Use
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    in a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match">
     <code class="leafygreen-ui-1l06pbn">
      $match
     </code>
    </a>
    stage to create a filter that matches documents in a
range of dates defined by a starting point (
    <code class="leafygreen-ui-1l06pbn">
     $purchaseDate
    </code>
    ) and a
time period given by
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    .
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.aggregate(\n   [\n      {\n         $match:\n            {\n               $expr:\n                  {\n                     $gt:\n                        [ \"$deliveryDate\",\n                          {\n                             $dateAdd:\n                                {\n                                   startDate: \"$purchaseDate\",\n                                   unit: \"day\",\n                                   amount: 5\n                                }\n                           }\n                        ]\n                  }\n            }\n       },\n       {\n          $project:\n             {\n                _id: 0,\n                custId: 1,\n                purchased:\n                   {\n                       $dateToString:\n                          {\n                             format: \"%Y-%m-%d\",\n                             date: \"$purchaseDate\"\n                          }\n                   },\n                delivery:\n                   {\n                      $dateToString:\n                         {\n                            format: \"%Y-%m-%d\",\n                            date: \"$deliveryDate\"\n                         }\n                   }\n             }\n       }\n   ]\n)","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">shipping</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">$match</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">$expr</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$gt</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->[ <span class="lg-highlight-string">"$deliveryDate"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                          <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                             <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                   <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$purchaseDate"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                   <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                   <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">5</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">             <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <span class="lg-highlight-attr">purchased</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                       <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                          <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                             <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                             <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$purchaseDate"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                          }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                   }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <span class="lg-highlight-attr">delivery</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                      <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                         <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                            <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                            <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$deliveryDate"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                         }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">             }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match">
     <code class="leafygreen-ui-1l06pbn">
      $match
     </code>
    </a>
    stage uses
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/gt/#mongodb-expression-exp.-gt">
     <code class="leafygreen-ui-1l06pbn">
      $gt
     </code>
    </a>
    and
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    in
an expression (
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
     <code class="leafygreen-ui-1l06pbn">
      $expr
     </code>
    </a>
    ) to compare the actual
    <code class="leafygreen-ui-1l06pbn">
     deliveryDate
    </code>
    with an expected date. Documents with delivery dates more than 5 days
after the
    <code class="leafygreen-ui-1l06pbn">
     purchaseDate
    </code>
    are passed on to the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
     <code class="leafygreen-ui-1l06pbn">
      $project
     </code>
    </a>
    stage.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
     <code class="leafygreen-ui-1l06pbn">
      $project
     </code>
    </a>
    stage uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString">
     <code class="leafygreen-ui-1l06pbn">
      $dateToString
     </code>
    </a>
    expression to convert the dates to a more readable format. Without the
conversion, MongoDB returns the date in
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ISODate">
     ISODate
    </a>
    format and
assumes a UTC timezone.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In this example only one record is returned:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"custId\" : 456, \"purchased\" : \"2020-12-31\", \"delivery\" : \"2021-01-10\" }","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-tyg50d">
      <pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">456</span>, <span class="lg-highlight-string">"purchased"</span> <!-- -->: <span class="lg-highlight-string">"2020-12-31"</span>, <span class="lg-highlight-string">"delivery"</span> <!-- -->: <span class="lg-highlight-string">"2021-01-10"</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Adjust for Daylight Savings Time
    <a class="headerlink leafygreen-ui-1kepx47" href="#adjust-for-daylight-savings-time" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="adjust-for-daylight-savings-time">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    All dates are stored internally in UTC time. When a
    <code class="leafygreen-ui-1l06pbn">
     timezone
    </code>
    is
specified,
    <code class="leafygreen-ui-1l06pbn">
     $dateAdd
    </code>
    uses local time to carry out the calculations.
The results are displayed in UTC.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    You have customers in several timezones and you want to see what effect
daylight savings time might have on your billing periods if you bill by
    <code class="leafygreen-ui-1l06pbn">
     day
    </code>
    or by
    <code class="leafygreen-ui-1l06pbn">
     hour
    </code>
    .
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Create this collection of connection times:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.billing.insertMany(\n   [\n      {\n         location: \"America/New_York\",\n         login: ISODate(\"2021-03-13T10:00:00-0500\"),\n         logout: ISODate(\"2021-03-14T18:00:00-0500\")\n      },\n      {\n         location: \"America/Mexico_City\",\n         login: ISODate(\"2021-03-13T10:00:00-00:00\"),\n         logout: ISODate(\"2021-03-14T08:00:00-0500\")\n      }\n   ]\n)","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">billing</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"America/New_York"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">login</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-13T10:00:00-0500"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">logout</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-14T18:00:00-0500"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"America/Mexico_City"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">login</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-13T10:00:00-00:00"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">logout</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-14T08:00:00-0500"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    First add 1 day, then add 24 hours to the
    <code class="leafygreen-ui-1l06pbn">
     login
    </code>
    dates in each
document.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.billing.aggregate(\n   [\n      {\n         $project:\n            {\n               _id: 0,\n               location: 1,\n               start:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date: \"$login\"\n                        }\n                  },\n               days:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date:\n                              {\n                                 $dateAdd:\n                                    {\n                                       startDate: \"$login\",\n                                       unit: \"day\",\n                                       amount: 1,\n                                       timezone: \"$location\"\n                                    }\n                              }\n                        }\n                  },\n               hours:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date:\n                              {\n                                 $dateAdd:\n                                 {\n                                    startDate: \"$login\",\n                                    unit: \"hour\",\n                                    amount: 24,\n                                    timezone: \"$location\"\n                                 }\n                              }\n                        }\n                  },\n               startTZInfo:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date: \"$login\",\n                           timezone: \"$location\"\n                        }\n                  },\n               daysTZInfo:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date:\n                              {\n                                 $dateAdd:\n                                    {\n                                       startDate: \"$login\",\n                                       unit: \"day\",\n                                       amount: 1,\n                                       timezone: \"$location\"\n                                    }\n                              },\n                           timezone: \"$location\"\n                        }\n                  },\n               hoursTZInfo:\n                  {\n                     $dateToString:\n                        {\n                           format: \"%Y-%m-%d %H:%M\",\n                           date:\n                              {\n                                 $dateAdd:\n                                    {\n                                       startDate: \"$login\",\n                                       unit: \"hour\",\n                                       amount: 24,\n                                       timezone: \"$location\"\n                                    }\n                              },\n                           timezone: \"$location\"\n                        }\n                  },\n            }\n      }\n   ]\n).pretty()","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">billing</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">start</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$login"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">days</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">hours</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"hour"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">startTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">daysTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">hoursTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                     <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">date</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                 <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"hour"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                       <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                                    }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                              }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                           <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-function">pretty</span>(<!-- -->)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString">
     <code class="leafygreen-ui-1l06pbn">
      $dateToString
     </code>
    </a>
    expression reformats the output for
readability. Results are summarized here:
   </p>
   <div class="leafygreen-ui-skkc39" tabindex="0">
    <table class="leafygreen-ui-hr8lsv">
     <thead class="leafygreen-ui-a9ho40">
      <tr data-testid="leafygreen-ui-header-row">
       <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Field
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          New York
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Mexico City
         </div>
        </div>
       </th>
      </tr>
     </thead>
     <tbody>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Start
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-13 15:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-13 10:00
         </div>
        </div>
       </td>
      </tr>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Start, TZ Info
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-13 10:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-13 04:00
         </div>
        </div>
       </td>
      </tr>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          1 Day
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 14:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 10:00
         </div>
        </div>
       </td>
      </tr>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          1 Day, TZ Info
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 10:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 04:00
         </div>
        </div>
       </td>
      </tr>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          24 Hours
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 15:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 10:00
         </div>
        </div>
       </td>
      </tr>
      <tr class="leafygreen-ui-15dvrnp">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          24 Hours, TZ Info
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 11:00
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          2021-03-14 04:00
         </div>
        </div>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The chart highlights several points:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      Unformatted dates are returned in UTC. The
      <code class="leafygreen-ui-1l06pbn">
       $login
      </code>
      for New York is
UTC -5, however the
      <code class="leafygreen-ui-1l06pbn">
       start
      </code>
      ,
      <code class="leafygreen-ui-1l06pbn">
       days
      </code>
      , and
      <code class="leafygreen-ui-1l06pbn">
       hours
      </code>
      rows display
the time in UTC.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      March 14th is the start of DST in New York, but not in Mexico. The
calculated time is adjusted when a location switches to DST and
crosses from one
      <code class="leafygreen-ui-1l06pbn">
       day
      </code>
      to the next.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      DST modifies the length of the
      <code class="leafygreen-ui-1l06pbn">
       day
      </code>
      , not the
      <code class="leafygreen-ui-1l06pbn">
       hour
      </code>
      . There is no
DST change for
      <code class="leafygreen-ui-1l06pbn">
       hours
      </code>
      . There is an only an adjustment for DST when
the measurement
      <code class="leafygreen-ui-1l06pbn">
       unit
      </code>
      is
      <code class="leafygreen-ui-1l06pbn">
       day
      </code>
      or larger and the computation
crosses a clock change in the specified
      <code class="leafygreen-ui-1l06pbn">
       timezone
      </code>
      .
     </p>
    </li>
   </ul>
   <div class="leafygreen-ui-13vw3ie" role="note">
    <h2 class="leafygreen-ui-1fn4p2b">
     Tip
    </h2>
    <h3 class="leafygreen-ui-144d5kf">
     <strong>
      See also:
     </strong>
    </h3>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateSubtract/#mongodb-expression-exp.-dateSubtract">
       <code class="leafygreen-ui-1l06pbn">
        $dateSubtract
       </code>
      </a>
      ,
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateDiff/#mongodb-expression-exp.-dateDiff">
       <code class="leafygreen-ui-1l06pbn">
        $dateDiff
       </code>
      </a>
     </p>
    </div>
   </div>
  </section>
 </section>
</section>
