Atmel Software Framework

Calculate time between dates

The use case will let the user calculate the time between two dates, by first calculating the dates from two timestamps.

Setup steps


For the code of this use case to work, the following must be added to the project:

  1. Three date structs:
    struct calendar_date result;
    struct calendar_date end_date;
    struct calendar_date start_date;
  2. Two timestamps:
    uint32_t end_timestamp = 1309174659;
    uint32_t start_timestamp = 123456789;

Example code

No setup code is needed, the service is ready for use as-is.

Usage steps

Example code

Add to, e.g. the main loop in the application C-file:

calendar_timestamp_to_date(end_timestamp, &end_date);
calendar_timestamp_to_date(start_timestamp, &start_date);
calendar_time_between_dates(&end_date, &start_date, &result);


  1. Convert the end timestamp to date:
  2. Convert the start timestamp to date:
  3. Calculate the time between the two dates: