Dart Duration inDays
Syntax & Examples


Duration.inDays property

The `inDays` property in Dart returns the number of whole days spanned by this Duration.


Syntax of Duration.inDays

The syntax of Duration.inDays property is:

 int inDays 

This inDays property of Duration returns the number of whole days spanned by this Duration.

Return Type

Duration.inDays returns value of type int.



✐ Examples

1 Duration with days and hours

In this example,

  1. We create a Duration object duration with 5 days and 12 hours.
  2. We use the inDays property to get the number of days as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(days: 5, hours: 12);
  int days = duration.inDays;
  print('Number of days: $days');
}

Output

Number of days: 5

2 Duration with days and hours

In this example,

  1. We create a Duration object duration with 3 days and 6 hours.
  2. We use the inDays property to get the number of days as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(days: 3, hours: 6);
  int days = duration.inDays;
  print('Number of days: $days');
}

Output

Number of days: 3

3 Duration with days and hours

In this example,

  1. We create a Duration object duration with 10 days and 18 hours.
  2. We use the inDays property to get the number of days as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(days: 10, hours: 18);
  int days = duration.inDays;
  print('Number of days: $days');
}

Output

Number of days: 10

Summary

In this Dart tutorial, we learned about inDays property of Duration: the syntax and few working examples with output and detailed explanation for each example.