I have two strings that represent times, for example:
timeA: 11:00 PM
timeB: 5:00 AM
I need to figure out if both of these times fall on the same day. So in the above example, since timeB is 5:00 AM, timeB is the next day. If timeA was 1:00 AM, then both are on the same day.
My initial thinking was to figure out the time until midnight from both timeA and timeB and decide that way if one falls on the next day, but I'm not able to bring my thoughts together in syntax (C# or VB.NET)
Isn't it safe to assume that if timeA is after timeB, then timeB is the next day? This is assuming that they are chronological.
So, in code:
public bool IsDifferentDays(DateTime time1, DateTime time2) {
if (time1 > time2) {
return true;
}
return false;
}
A bit of coding:
bool isTimeBInNextDay = DateTime.ParseExact(timeB, @"h\:mm tt", null) < DateTime.ParseExact(timeA, @"h\:mm tt", null);
I have two strings that represent times, for example:
timeA: 11:00 PM
timeB: 5:00 AM
I need to figure out if both of these times fall on the same day. So in the above example, since timeB is 5:00 AM, timeB is the next day. If timeA was 1:00 AM, then both are on the same day.
My initial thinking was to figure out the time until midnight from both timeA and timeB and decide that way if one falls on the next day, but I'm not able to bring my thoughts together in syntax (C# or VB.NET)
Isn't it safe to assume that if timeA is after timeB, then timeB is the next day? This is assuming that they are chronological.
So, in code:
public bool IsDifferentDays(DateTime time1, DateTime time2) {
if (time1 > time2) {
return true;
}
return false;
}
A bit of coding:
bool isTimeBInNextDay = DateTime.ParseExact(timeB, @"h\:mm tt", null) < DateTime.ParseExact(timeA, @"h\:mm tt", null);
0 commentaires:
Enregistrer un commentaire