Getting the number of days between two different dates

Discussion in 'Programming & Scripting' started by gunfreak010, Jan 25, 2009 with 2 replies and 210 views.

  1. gunfreak010

    gunfreak010 Enthusiast

    Messages:
    21
    Ratings:
    0
    Don't ask why or how I found it, but I did... Its actually pretty cool since I dont believe that there exists anything in C# that does what im about to show you... :x3:

    Anyways, here is the code (It requires a calendar control!)


    Code:
    int difference = 0;
    
    private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
    {
    int today = int.Parse(((monthCalendar1.TodayDate.Ticks) / (864000000000)).ToString());
    int select = int.Parse(((e.End.Ticks) / (864000000000)).ToString());
    difference = (today - select);
    textBox2.Text = difference.ToString();  
    }
    
    Basically, the dividing by 864000000000 tells us what number of the day we are in for the ENTIRE AD PERIOD OF TIME.... wow! XD

    I honestly have a generous use for this piece of code, because im producing a "calculator" sort of thing, and one of the statistics is your longevity on a site, so I thought I would find this to help :smile: Its amazing what you can find if your up to do a little math :smile:

    Lol, needed help, but all I had to do was remove the todaydate code from the windows form generated code >.> So stupid...
     
  2. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
    Well if your not using a calendar control and you just wanted to get the days between two dates you could do this.
    Code:
    DateTime day1 = DateTime.Parse("1/20/09");
    DateTime day2 = DateTime.Parse("1/25/09");
    MessageBox.Show((day2 - day1).TotalDays.ToString());
    
    Never even knew there was a calendar control. Crazy all of the things they have for you.
     
  3. OP
    gunfreak010

    gunfreak010 Enthusiast

    Messages:
    21
    Ratings:
    0
    Lmao, already there is something better posted! Man im so noob XD Thanks for that, though! And yeah, they have a lot, and its just so useful! XD