Skip to content

A Flutter package to calculate someone's age in days, months, and years; in addition, it can be used to find the difference between two dates.

License

Notifications You must be signed in to change notification settings

mihirpipermitwala/how_old_am_i

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

how_old_am_i

pub package

A Flutter package to calculate someone's age in days, months, and years; in addition, it can be used to find the difference between two dates.

Installtion

  1. Add this to your package's pubspec.yaml file:
dependencies:
  how_old_am_i: any

Example

import 'package:how_old_am_i/how_old_am_i.dart';

void main() {
  DateTime dateOfBirth = DateTime(1992, 7, 31);

  DateTimeDuration dateTimeDuration;

  // Find out your age as of today's date
  dateTimeDuration = HowOldAmI.age(dateOfBirth);
  print('Your age is ' + dateTimeDuration.toString());

  //Find out your age on any given date
  dateTimeDuration = HowOldAmI.age(dateOfBirth, today: DateTime(2030, 5, 1));
  print('Your age is $dateTimeDuration');

  // Find out when your next birthday will be
  dateTimeDuration = HowOldAmI.timeToNextBirthday(dateOfBirth);
  print('You next birthday will be in $dateTimeDuration');

  // Find out when your next birthday will be on any given date
  dateTimeDuration =
      HowOldAmI.timeToNextBirthday(dateOfBirth, fromDate: DateTime(2022, 8, 2));
  print('You next birthday will be in $dateTimeDuration');

  // Find out the difference between two dates
  dateTimeDuration = HowOldAmI.dateDifference(
    fromDate: DateTime.now(),
    toDate: DateTime(2025, 5, 2),
  );
  print('The difference is $dateTimeDuration');

  // Add time to any date
  DateTime date = HowOldAmI.add(
      date: DateTime.now(),
      duration: DateTimeDuration(years: 5, months: 2, days: 1));
  print(date);
}

About

A Flutter package to calculate someone's age in days, months, and years; in addition, it can be used to find the difference between two dates.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages