![]() Ok, so if you are familiar with the properties of the class then you will understand this thing properly. So, TimeSpan is a class that has properties like Days, Hours, Minutes, Seconds, Milliseconds. So, firstly I will explain TimeSpan in two lines. Ok, so now you have checked to declare the variable of time span and store the value of the difference now what. So, for that check out the following snippet, TimeSpan span = startTime.Subtract ( dateFromString ) //Perform to Find the Difference So, we are using the time span to perform the subtract operation and to get them all differences. am I right? Ok, so let me just check with you you think I am going to just subtract the date like (Date1 - Date2 ) and store it to another DateTime variable. Now, you might think like that what is the short form or the easier form here. DateTime startTime = DateTime.Now //Current Date Follow the following snippet to get the current date. Now, you will see we got the date on which we want to perform the operations now what about the current date. string stringDate = " 6:19:02 AM" //If Date is in String Format.ĭateTime dateFromString = DateTime.Parse(stringDate) //Parse the String to the DateTime So, let's just check out the following snippet to check how the parsing is going to be done for the string to DateTime. So, the simple solution is to Conver it or parse it to the DateTime it is simple right. So, now the situation is something like that the second date on which we want to perform the difference operations is in the string format and the current date is in the DateTime Format. So, we have a DateTime Variable, one is the start date and the second one is the end date. Today, we are not going to discuss too much about the other things like how we were used to finding the difference before I will just directly move to the concept which we are going to use today. Once again I am back with some cool and easy ways to find the difference between two dates in the C#.
0 Comments
Leave a Reply. |