Skip to content

DateTime application

reginald knight

Asked Feb 21, 2007, 4:03 AM EST9 answers
Share
LinkedInX
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 Gold
    0
    Code
    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 G
    0
  • 0

    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 G
    0
  • 0
    is it that the finishtime isnt included in the result? im not sure since you didnt get into specifics, but if it is, just calculate


    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
    0
  • 0
    What I'm not able to do is enter the FinishDate myself. The calculation is fine.
    0
  • 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*

    cheers
    adam
    0
  • 0
    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);


    Thanks
    0
  • 0
    ah, ok i see where you are starting to get at... could you post the entire sub? as well as the complete query you are using... cheers :) adam
    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);

    System.TimeSpan intDays=dtmFinishDate.Subtract(dtmStartDate);

    txtDays.Text=Convert.ToString( intDays );

    0
  • Mike Gold
    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);
    0