mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
3902f9a476
7030fe3a2 Remove .hvm file dd0f98831 Add details for DigitalOcean (#1730) ff0c8a6e7 netlify: Hugo 0.97.3 e254724a7 Delete hosting-on-bitbucket.md (#1723) f4304fb7e Remove references to mmark (#1727) 255319023 remove broken link to codeplex.com (#1725) 06cc3856b delete broken link (#1724) ec80dc069 Revert "netlify: Hugo 0.97.2" 211bad5de netlify: Hugo 0.97.2 cd549bca9 Revert "netlify: Update to Hugo 0.97.1" (#1722) 1039a0a48 netlify: Update to Hugo 0.97.1 a28e0d0d3 Update AddDate method 9077b443f Update lists.md 6b174329a Update lists.md d87d9e296 netlify: Hugo 0.97.0 fa7db7c7e Merge branch 'tempv0.97.0' dd6df54b5 Fix broken anchor links (#1717) 6b6743976 Remove StackImpact showcase d00a7eda9 Fix for Cloudflare docs location (#1716) 890866722 Add git required FAQ & remove ZIP from Quick Start (#1713) 73e82d911 resources: Add `key` to reources.GetRemote options map 6795cd2a1 Correct possible typos re: Alias robots usage (#1165) efd5d186a Hosting on Cloudflare Pages (#1709) 9239c5f2a deps: Update github.com/tdewolff/minify/v2 v2.10.0 => v2.11.0 859573bc8 Merge commit 'ec920363cdeb687c8bcac9c242767d366fb058cb' 21f108f12 docs: Regen CLI docs 9b6e7afd2 Add environment as a new filter to _cascade.target git-subtree-dir: docs git-subtree-split: 7030fe3a2ea107a23a4442902cb693557a421523
45 lines
1.4 KiB
Markdown
45 lines
1.4 KiB
Markdown
---
|
|
title: .AddDate
|
|
description: Returns the time corresponding to adding the given number of years, months, and days to the given time.Time value.
|
|
date: 2017-02-01
|
|
publishdate: 2017-02-01
|
|
lastmod: 2017-02-01
|
|
categories: [functions]
|
|
menu:
|
|
docs:
|
|
parent: "functions"
|
|
keywords: [dates,time]
|
|
signature: [".AddDate YEARS MONTHS DAYS"]
|
|
workson: [times]
|
|
hugoversion:
|
|
relatedfuncs: [now]
|
|
deprecated: false
|
|
aliases: []
|
|
---
|
|
|
|
```go-html-template
|
|
{{ $d := "2022-01-01" | time.AsTime }}
|
|
|
|
{{ $d.AddDate 0 0 1 | time.Format "2006-01-02" }} --> 2022-01-02
|
|
{{ $d.AddDate 0 1 1 | time.Format "2006-01-02" }} --> 2022-02-02
|
|
{{ $d.AddDate 1 1 1 | time.Format "2006-01-02" }} --> 2023-02-02
|
|
|
|
{{ $d.AddDate -1 -1 -1 | time.Format "2006-01-02" }} --> 2020-11-30
|
|
```
|
|
|
|
{{% note %}}
|
|
When adding months or years, Hugo normalizes the final `time.Time` value if the resulting day does not exist. For example, adding one month to 31 January produces 2 March or 3 March, depending on the year.
|
|
|
|
See [this explanation](https://github.com/golang/go/issues/31145#issuecomment-479067967) from the Go team.
|
|
{{% /note %}}
|
|
|
|
```go-html-template
|
|
{{ $d := "2023-01-31" | time.AsTime }}
|
|
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} --> 2023-03-03
|
|
|
|
{{ $d := "2024-01-31" | time.AsTime }}
|
|
{{ $d.AddDate 0 1 0 | time.Format "2006-01-02" }} --> 2024-03-02
|
|
|
|
{{ $d := "2024-02-29" | time.AsTime }}
|
|
{{ $d.AddDate 1 0 0 | time.Format "2006-01-02" }} --> 2025-03-01
|
|
```
|