Hello guys..
I have a little problem.
I need to count the elapsed days between two dates.
Is not inportat to consider if a year is a leap year or not, but I need to show a warning message when a period about 3 years has expired starting from the installation date of the device.
Any Idea?
many thanks
Daysbetween
Hello Gianluca,
You must have the installation date stored into EEprom.
You must have the installation date stored into EEprom.
Code: Select all
function Date2NTP(year_ : word; month_, day_, hour_, min_, sec_: byte) : dword;
var day_buf : word;
begin
result := year_ - 1970;
result := result*365 + (result div 4);
case month_ of
1 : day_buf := day_;
2 : day_buf := day_ + 31;
3 : day_buf := day_ + (31 + 28);
4 : day_buf := day_ + (31 + 28 + 31);
5 : day_buf := day_ + (31 + 28 + 31 + 30);
6 : day_buf := day_ + (31 + 28 + 31 + 30 + 31);
7 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30);
8 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31);
9 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31);
10 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30);
11 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31)
else day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30);
end;
result := (result + day_buf) * 86400 + (hour_ * 3600) + (min_ * 60) + sec_ + 2208988800;
end;
Code: Select all
Read_Time(Sec, Min, Hr, Day, Mn ,Year);
Elapsed_Days = (Date2NTP(Year,Mn,Day,Hr,Min,Sec) - Date2NTP(Year_Stored,Mn_Stored,Day_Stored,Hr_Stored,Min_Stored,Sec_Stored)) div (24*3600);
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
-
- Posts: 26
- Joined: 31 May 2005 13:32
-
- Posts: 26
- Joined: 31 May 2005 13:32
I've just tried..yo2lio wrote:Hello Gianluca,
You must have the installation date stored into EEprom.
Code: Select all
function Date2NTP(year_ : word; month_, day_, hour_, min_, sec_: byte) : dword; var day_buf : word; begin result := year_ - 1970; result := result*365 + (result div 4); case month_ of 1 : day_buf := day_; 2 : day_buf := day_ + 31; 3 : day_buf := day_ + (31 + 28); 4 : day_buf := day_ + (31 + 28 + 31); 5 : day_buf := day_ + (31 + 28 + 31 + 30); 6 : day_buf := day_ + (31 + 28 + 31 + 30 + 31); 7 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30); 8 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31); 9 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31); 10 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30); 11 : day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) else day_buf := day_ + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30); end; result := (result + day_buf) * 86400 + (hour_ * 3600) + (min_ * 60) + sec_ + 2208988800; end;
Code: Select all
Read_Time(Sec, Min, Hr, Day, Mn ,Year); Elapsed_Days = (Date2NTP(Year,Mn,Day,Hr,Min,Sec) - Date2NTP(Year_Stored,Mn_Stored,Day_Stored,Hr_Stored,Min_Stored,Sec_Stored)) div (24*3600);
It works very well.
Thanks again and have a nice day.
Gianluca Colombo