https://github.com/rich-97/calc-age-js
A simple function for calculate the age from a date.
https://github.com/rich-97/calc-age-js
age calculate date javascript
Last synced: 5 months ago
JSON representation
A simple function for calculate the age from a date.
- Host: GitHub
- URL: https://github.com/rich-97/calc-age-js
- Owner: rich-97
- License: mit
- Created: 2017-07-17T04:06:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-27T21:54:56.000Z (over 8 years ago)
- Last Synced: 2025-08-21T06:56:51.178Z (11 months ago)
- Topics: age, calculate, date, javascript
- Language: JavaScript
- Size: 2.93 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calc-age-js
[](https://www.npmjs.com/package/calc-age)
[](https://www.npmjs.com/package/calc-age)
Simple function for calculate the age of a person from a date. This package can calculate the age in years, months and days.
## Installation
Via `npm`:
```shell
npm install calc-age
```
## Usage
Simple example:
```js
const calcAge = require('calc-age')
const date = { year: 1989, month: 3, day: 9 }
const myAge = calcAge(date)
console.log(myAge.years) // Should be equal to 28 (current year: 2017).
```
This function also accept an string as number, the following object is valid:
```js
const date = { year: '1989', month: '3', day: '9' }
```
If you use an string as number, the string always should be only one or more digits.