# dated - Simplifying DateTime Operations in Dart

> The new Dart package 'dated' simplifies working with dates and times. It offers easy comparisons, 'time ago' calculations, and customization options for your projects. Check out the documentation and contribute on GitHub!

- Author: [Azraf Al Monzim](https://monzim.com/)
- Published: 2024-05-11
- Updated: 2026-06-13
- Topic: Flutter & Dart
- Canonical: https://monzim.com/blog/dated-simplifying-datetime-operations-in-dart

---

Do you find yourself constantly juggling **DateTime** objects in your Dart projects? Wish there was a simpler way to compare dates, check if they're within the same period, or calculate how much time has passed? Say hello to your new best friend: the _**dated**_ package!

**Why dated?**

The **DateTime** class in Dart is powerful, but it can sometimes feel a bit verbose. _**dated**_ gives you a suite of handy extensions that make working with dates a breeze. Here's what you can do:

- **Effortless Comparisons:** No more complex logic to check if two dates are on the same day, month, or year. With _**dated**_, it's as simple as:

  ```dart
  DateTime today = DateTime.now();
  DateTime yesterday = today.subtract(const Duration(days: 1));

  if (today.isSameDay(yesterday)) {
    // This won't happen!
  }
  ```

- **Time Ago Like a Pro:** Ever wanted to display a friendly "2 hours ago" or "3 months ago" message? _**dated**_ does the heavy lifting for you:

  ```dart
  DateTime oldPost = DateTime.now().subtract(const Duration(days: 120));
  String timeAgo = oldPost.timeAgo(); // Returns "4 months ago"
  ```

- **Flexible API:** Customize your time ago strings with prefixes and suffixes to perfectly fit your app's design:

  ```dart
  // Returns "Posted 4 months ago"
  String withPrefix = oldPost.timeAgo(prefix: "Posted");
  ```

**Installation & Getting Started**

It's a snap to get _**dated**_ working in your project:

1.  **Add to pubspec:**

    ```bash
    dart pub add dated
    ```

2.  **Import:**

    ```dart
    import 'package:dated/dated.dart';
    ```

3.  **Start Coding!**

**A Quick Example**

Let's see how _**dated**_ simplifies a common task: figuring out if a product's warranty is still valid:

```dart
DateTime purchaseDate = DateTime.parse("2024-01-15");
DateTime today = DateTime.now();

int warrantyMonths = 12;
DateTime warrantyExpires = purchaseDate.add(Duration(days: warrantyMonths * 30));

if (today.isBeforeDay(warrantyExpires)) {
    print("Your warranty is still active!");
} else {
    print("Your warranty has expired.");
}
```

**Explore the Full Potential**

This just scratches the surface! Check out the _**dated**_ package documentation for a full list of methods and options.

**Contribute & Give Feedback**

**GitHub: [monzim/dated](https://github.com/monzim/dated)**

**PubDev: [https://pub.dev/packages/dated](https://pub.dev/packages/dated)**

We believe in open source! If you find any issues, have ideas for new features, or just want to chat, head over to the GitHub repository and join the discussion. Let's make date handling in Dart even better together!

**Let's Get Dated!**

We hope you're as excited about _**dated**_ as we are. Give it a spin in your next Dart project and let us know what you think! Happy coding!
