Can anyone help me with this? I'm trying to calculate the number of days of a start and a finish date and put the result of days in a textbox. The problem I'm having is the conversion, I'm getting 243.00:00:00 mailto:[email protected]. Also put result on forum
Here's the code:
Code
System.DateTime dtmStartDate = new System.DateTime(2007,1,1);
System.DateTime dtmFinishDate = new System.DateTime(2007,9,1);
System.TimeSpan intDays=dtmFinishDate.Subtract(dtmStartDate);
txtDays.Text=Convert.ToString( intDays );
9 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted Feb 21, 2007, 2:32 PM EST
Mike: A few weeks ago I asked for help with the below method, and it worked fabulous,however, I'm having another problem being able to input my own FinishDate.
Thanks, Reginald
System.DateTime dtmStartDate = new System.DateTime(2007, 1, 1);
System.DateTime dtmFinishDate = new System.DateTime(2007, 9, 1);
Adam Grande23 pointsPosted Mar 14, 2007, 3:29 PM EDT
0
oh um ok... thats a tad weird... what do you mean you cant input your own finish date? just grab the date value from whatever control you are using... i think i have the wrong end of the stick here, can you please clarify why you cant input your finish date? is it a limitation of the application? im a tad confused... its really early and im really tired! *sheepish grin*
Adam:what I'm saying is that it's not that I can't input the finish date that's passed. I want to input my own date and then pass it. I have tried passing it as this but doesn't work. (dtmFinishDate.Year, dtmFinishDate.Month, dtmFinishDate.Day, 0,0,0);
Can anyone help: I'm trying to get the number of days entering my finish date. I'm getting an error passing the Year, Month, Day. I'm using academic visual studio 2003 c#
System.DateTime dtmStartDate = new System.DateTime(2007,1,1);
System.DateTime dtmFinishDate = new System.DateTime(dtmFinishDate.Year, dtmFinishDate.Month, dtmFinishDate.Day);
Mike GoldRank #50 · 30.6K pointsPosted Mar 19, 2007, 1:59 PM EDT
0
Hi reginald
I guess we are still a little confused at what you want to do because it's not clear in your question, so I'll attempt to guess and you can pick one of the options.
a) You want to populate a date time control with your own date time
Code
DateTimePicker1.Value = new DateTime(2001, 10, 20);
b) You want to create your own finish date from another DateTime instance?
DateTime dtFinish = new DateTime(2001, 10, 20);
Mike GoldRank #50 · 30.6K pointsPosted Feb 21, 2007, 2:32 PM EST
reginald knight16 pointsPosted Mar 9, 2007, 4:59 AM EST
Mike: A few weeks ago I asked for help with the below method, and it worked fabulous,however, I'm having another problem being able to input my own FinishDate.
Thanks,
Reginald
System.DateTime dtmStartDate = new System.DateTime(2007, 1, 1);
System.DateTime dtmFinishDate = new System.DateTime(2007, 9, 1);
System.TimeSpan intDays = dtmFinishDate - dtmStartDate;
textBox1.Text = intDays.TotalDays.ToString();
-Mike GAdam Grande23 pointsPosted Mar 13, 2007, 6:31 PM EDT
System.TimeSpan ts = (finishtime.adddays(1)) - starttime
//rest of your code here
if im way off, please let me know and ill try to help some more
regards
adam
reginald knight16 pointsPosted Mar 14, 2007, 6:29 AM EDT
Adam Grande23 pointsPosted Mar 14, 2007, 3:29 PM EDT
cheers
adam
reginald knight16 pointsPosted Mar 15, 2007, 6:11 AM EDT
I have tried passing it as this but doesn't work.
(dtmFinishDate.Year, dtmFinishDate.Month, dtmFinishDate.Day, 0,0,0);
Thanks
Adam Grande23 pointsPosted Mar 16, 2007, 8:25 PM EDT
reginald knight16 pointsPosted Mar 19, 2007, 9:04 AM EDT
Can anyone help: I'm trying to get the number of days entering my finish date. I'm getting an error passing the Year, Month, Day. I'm using academic visual studio 2003 c#
System.DateTime dtmStartDate = new System.DateTime(2007,1,1);
System.DateTime dtmFinishDate = new System.DateTime(dtmFinishDate.Year, dtmFinishDate.Month, dtmFinishDate.Day);
System.TimeSpan intDays=dtmFinishDate.Subtract(dtmStartDate);
txtDays.Text=Convert.ToString( intDays );
Mike GoldRank #50 · 30.6K pointsPosted Mar 19, 2007, 1:59 PM EDT
I guess we are still a little confused at what you want to do because it's not clear in your question, so I'll attempt to guess and you can pick one of the options.
a) You want to populate a date time control with your own date time