compare Date and Time
-
Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj
Sarfarj Ahmed
-
Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj
Sarfarj Ahmed
If string to DateTime conversion is yur problem then u can use, Convert.ToDateTime("10/02/2009 03:37:25") to make a DateTime object of your string. Alternately, DateTime.Parse. For comparing, http://www.codeproject.com/script/Forums/View.aspx?fid=12076&select=2917783&fr=1#xx2917783xx[^]
-
If string to DateTime conversion is yur problem then u can use, Convert.ToDateTime("10/02/2009 03:37:25") to make a DateTime object of your string. Alternately, DateTime.Parse. For comparing, http://www.codeproject.com/script/Forums/View.aspx?fid=12076&select=2917783&fr=1#xx2917783xx[^]
Actualy I want to calculate wheather customer date and time (input from customer) is 8 hours more than system date and time or not. Anyway, Thank you very much for replying
Sarfarj Ahmed
-
Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj
Sarfarj Ahmed
DateTime Dt= DateTime.Parse("10/02/2009 03:37:25"); DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00"); TimeSpan t = Dt.Subtract(Dt2); MessageBox.Show(t.TotalHours.ToString());
Now From Time Span you can get the time Difference ;)
cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net
-
DateTime Dt= DateTime.Parse("10/02/2009 03:37:25"); DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00"); TimeSpan t = Dt.Subtract(Dt2); MessageBox.Show(t.TotalHours.ToString());
Now From Time Span you can get the time Difference ;)
cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net
Dear Abhijit Jana Thanks you very much. You are a STAR Thanks Sarfaraj
Sarfarj Ahmed
-
DateTime Dt= DateTime.Parse("10/02/2009 03:37:25"); DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00"); TimeSpan t = Dt.Subtract(Dt2); MessageBox.Show(t.TotalHours.ToString());
Now From Time Span you can get the time Difference ;)
cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net
It looks like the date OP is talking about is in dd/mm/yyyy format. If yes, your code will fail. It will take 02 as date and 10 as month. You need to use
DateTime.ParseExact
with an invariant culture and required format. :)Navaneeth How to use google | Ask smart questions