github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/adddate.md (about)

     1  ---
     2  title: .AddDate
     3  description: Returns the time corresponding to adding the given number of years, months, and days passed to the function.
     4  godocref: https://golang.org/pkg/time/#Time.AddDate
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [functions]
     9  menu:
    10    docs:
    11      parent: "functions"
    12  keywords: [dates,time]
    13  signature: [".AddDate YEARS MONTHS DAYS"]
    14  workson: [times]
    15  hugoversion:
    16  relatedfuncs: [now]
    17  deprecated: false
    18  aliases: []
    19  ---
    20  
    21  
    22  The `AddDate` function takes three arguments in logical order of `years`, `months`, and `days`.
    23  
    24  ## Example: Randomized Tweets from the Last 2 Years
    25  
    26  Let's assume you have a file at `data/tweets.toml` that contains a list of Tweets to display on your site's homepage. The file is filled with `[[tweet]]` blocks; e.g.---
    27  
    28  ```
    29  [[tweet]]
    30  name = "Steve Francia"
    31  twitter_handle = "@spf13"
    32  quote = "I'm creator of Hugo. #metadocreference"
    33  link = "https://twitter.com/spf13"
    34  date = "2017-01-07T00:00:00Z"
    35  ```
    36  
    37  Let's assume you want to grab Tweets from the last two years and present them in a random order. In conjunction with the [`where`](/functions/where/) and [`now`](/functions/now/) functions, you can limit our range to the last two years via `now.AddDate -2 0 0`, which represents a point in time 2 years, 0 days, and 0 hours before the time of your last site build.
    38  
    39  {{< code file="partials/templates/random-tweets.html" download="tweets.html" >}}
    40  {{ range where $.Site.Data.tweets.tweet "date" "ge" (now.AddDate -2 0 0) | shuffle }}
    41      <div class="item">
    42          <blockquote>
    43              <p>
    44              {{ .quote | safeHTML }}
    45              </p>
    46              &mdash; {{ .name }} ({{ .twitter_handle }}) <a href="{{ .link }}">
    47                  {{ dateFormat "January 2, 2006" .date }}
    48              </a>
    49          </blockquote>
    50      </div>
    51  {{ end }}
    52  {{< /code >}}