Days Count?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pskvenkat
    New Member
    • Mar 2008
    • 10

    #1

    Days Count?

    Hi,
    I have two fileds
    1. FromDate
    2.ToDate

    Days= FromDatetextbox .text – ToDateTextBox.t ext;

    The result i want like
    Days = 18/04/2008 - 22/04/2008;
    Response.write( Days);
    Result is : 4

    How will i get this kind of result?
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi pskvenkat,

    You can calculate the difference, in days, between two dates using the following example. The Days property simply returns the number of whole days represented by the time difference.
    Code:
     Dim a, b 
    Dim Days As Int16
    a = Date.Parse(FromDateTextBox.text)
    b = Date.Parse(ToDateTextBox.text)
    Days = (b - a).Days
    This is in VB but i'm sure you can convert it to C# if required without too much difficulty.

    Hope this helps,

    Dr B
    Last edited by DrBunchman; Apr 16 '08, 09:39 AM. Reason: Getting rid of format tags!!

    Comment

    • pskvenkat
      New Member
      • Mar 2008
      • 10

      #3
      Thanks i got it,
      code is like this

      TimeSpan datediff = Convert.ToDateT ime(TextBox2.Te xt) - Convert.ToDateT ime(TextBox1.Te xt);

      TextBox3.Text = datediff.ToStri ng();

      Comment

      Working...