Compare period of date

How I can to create an interval between dates. I need a cin for the two interval and verify the temperature in the list, survey of occurrences of a given temperature in a period, showing how many times the temperature was greater than 25ºC.
My list insere in this order
1
2
3
4
	friend std::ostream& operator<<(std::ostream& os, const Estado &e) {
		os << e._dataHora << ";" << e._temperatura << ";" << e._res << ";"<< e._vent;
		return os;
	}

My class DataHora return this:

1
2
3
4
	friend ostream& operator<<(std::ostream& os, const DataHora & dh) {
		os << dh._dia << ";" << dh._mes << ";" << dh._ano << ";" << dh._hora<< ";" << dh._minuto << ";" << dh._segundo;
		return os;
	}


I need to go through the list and compare the values ​​of dataHora of list. My list is:
1
2
3
4
5
6
7
8
9
10
11
12
13
template<typename T>
void ListaEncadeada<T>::insereF(T x) { //Adiciona um elemento ao final da lista
	Elemento<T> *novo = new Elemento<T>(x); // Aloca espaço de memória
	tam++;
	if (!cabeca) // Lista vazia
		cabeca = novo;
	else { // Lista já tem elementos
		Elemento<T> *onde = cabeca;
		while (onde->prox) // Enquanto não for o último elemento
			onde = onde->prox;
		onde->prox = novo;
	}
}

In the menu I have this option:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
		case 0: {
			c_clrscr();
			Estado _estado = _interface.getEstado();
			lista.insereF(_estado);
			break;
		}

	Estado getEstado() {
		string _leitura = _s.enviaSerial(0);
		replace(_leitura.begin(), _leitura.end(), '.', ',');
		_temperatura = atof(_leitura.c_str());
		cout << _temperatura << endl;
		Controle();
		return Estado(_temperatura, _dataHora, _vent, _res);
	}
Working with time is notoriously difficult. There are timezones to consider and daylight savings time and leap years and leap seconds, etc. The best way to compare two times is to convert the day/month/year/hours/minutes/seconds into the number of seconds from a specific point in time, and then compare the offsets.

Fortunately, C++ lets you do this:
http://www.cplusplus.com/reference/ctime/mktime/
http://www.cplusplus.com/reference/ctime/localtime/

You might want to consider storing the time as a time_t and converting to/from a date and time when you input and output the value.
I have this functions and I can save date and tima in the list, but I need to compare the saved times of list.
> How I can to create an interval between dates

Convert local calendar time to time since epoch (convert to std::time_t)
Use std::mktime https://en.cppreference.com/w/cpp/chrono/c/mktime

To portably compute the time interval (in seconds), use std::difftime
https://en.cppreference.com/w/cpp/chrono/c/difftime


> I need to compare the saved times of list

The standard does not specify in what units time since epoch should be measured;
but it does guarantee that std::time_t is some arithmetic type.
Compare them like we would compare any arithmetic type (==, < etc.)
Topic archived. No new replies allowed.