https://github.com/antklim/datediff
Go package to calculate dates difference
https://github.com/antklim/datediff
datetime go golang golang-package
Last synced: 11 months ago
JSON representation
Go package to calculate dates difference
- Host: GitHub
- URL: https://github.com/antklim/datediff
- Owner: antklim
- License: mit
- Created: 2022-03-09T23:12:51.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T21:11:01.000Z (over 1 year ago)
- Last Synced: 2025-01-05T01:26:31.570Z (about 1 year ago)
- Topics: datetime, go, golang, golang-package
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# datediff
[](https://codecov.io/gh/antklim/datediff)
The `datediff` is the package to calculate dates difference. The standard `time` package provides functionality to calculate time difference. The returned result is `time.Duration`. Working with durations can be tricky, especially when we need to represent duration in full days, weeks, etc. This package provides the functionality to represent difference between two dates as the amount of full years, months, weeks, or days passed since the start date.
# Installation
`go get github.com/antklim/datediff`
# Usage
```go
package main
import(
"fmt"
"time"
"github.com/antklim/datediff"
)
func main() {
dateOfBirth, _ := time.Parse("2006-01-02", "2000-10-01")
today, _ := time.Parse("2006-01-02", "2010-11-30")
age, _ := datediff.NewDiff(dateOfBirth, today, "%Y %M %D")
fmt.Printf("Today I'm %s old", age)
// Output:
// Today I'm 10 years 1 month 29 days old
}
```