-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeStamp_comparisor.c
81 lines (76 loc) · 1.81 KB
/
TimeStamp_comparisor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Program for TimeStamp comparision in format " yy/MM/dd HH:mm:ss "
#include <stdio.h>
typedef struct TimeStamp{
int year;
int month;
int date;
int hour;
int minute;
int second;
}TimeStamp;
void display(TimeStamp t){
printf("The timestamp is: %d/%d/%d %d:%d:%d \n",t.year,t.month,t.date,t.hour,t.minute,t.second);
}
int TimeStampCmp(TimeStamp t1, TimeStamp t2){
// Make decission on the basis of year comparision
if(t1.year > t2.year){
return 1;
}
if(t1.year < t2.year){
return -1;
}
// Make decissionn on basis of month comparision
if(t1.month > t2.month){
return 1;
}
if(t1.month < t2.month){
return -1;
}
// Make decision on the basis of date comparision
if(t1.date > t2.date){
return 1;
}
if(t1.date < t2.date){
return -1;
}
// Make decission on the basis of hour comparision
if(t1.hour > t2.hour){
return 1;
}
if(t1.hour < t2.hour){
return -1;
}
// Make decissionn on basis of minute comparision
if(t1.minute > t2.minute){
return 1;
}
if(t1.minute < t2.minute){
return -1;
}
// Make decision on the basis of second comparision
if(t1.second > t2.second){
return 1;
}
if(t1.second < t2.second){
return -1;
}
return 0;
}
int main()
{
TimeStamp t1 = {21,12,17,13,10,15};
TimeStamp t2 = {20,11,25,11,44,10};
display(t1);
display(t2);
int r = TimeStampCmp(t1,t2);
if(r==1){
printf("TimeStamp one is latest as compared to second one\n");
}
else if(r==-1){
printf("TimeStamp one is older as compared to second one\n");
}
else{
printf("Both the TimeStamps are same\n");
}
return 0;
}