Convert String into Int data type and finally convert into DateTime for Compare two dates in C#

Hi
I have two string value and i want to convert into DATETIME so that , i can do difference between them
like below

string a= 07032011 12:50
string b= 07032011 23:40

DateTime aa = new DateTime(int.Parse(a.Substring(4, 4)), int.Parse(a.Substring(2, 2)),
                                         int.Parse(a.Substring(0, 2)), int.Parse(a.Substring(9, 2)), int.Parse(a.Substring(12, 2)),

                                         00);
            DateTime bb = new DateTime(int.Parse(b.Substring(4, 4)), int.Parse(b.Substring(2, 2)),
                                         int.Parse(b.Substring(0, 2)), int.Parse(b.Substring(9, 2)), int.Parse(b.Substring(12, 2)),

                                         00);
    TimeSpan cc = aa - bb;

ind day= cc.days;
int hour= cc.hours;
int minutes= cc.minutes;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.