Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:57:23+00:00 2026-06-18T14:57:23+00:00

I would really like some guidance on this problem i have been facing. I

  • 0

I would really like some guidance on this problem i have been facing.
I am trying to find out the difference between 2 dates from textbox.

   protected void Button1_Click(object sender, EventArgs e)
{
    a = TextBox1.Text.ToString().Trim();
    b = TextBox2.Text.ToString().Trim();
    DateTime c = new DateTime();
    DateTime d = new DateTime();
    c = Convert.ToDateTime(a);
    d = Convert.ToDateTime(b);
    System.TimeSpan diffr = d - c;
    Response.Write(diffr.Days);
}

The above is the code i have written on Button Click event.
The problem is that, the code returns the difference wrong.

i.e if the diff between 12/02/2013 and 11/02/2013 is to be found, instead of returning 1
the code returns 30.
Similarly diff between 12/02/2013 and 10/02/2013 is to be found, instead of returning 2
the code returns 61.

I am using the Jquery DatePicker for selecting the date!
Kindly help as all my search has not yielded any solutions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:57:24+00:00Added an answer on June 18, 2026 at 2:57 pm

    The only problem is the format of the date.
    As you have written it is showing the month difference rather than date difference.
    Try using datetime.parseexact and specify your format

    Example:-

     string poop = "2005-12-14T14:35:32.1700000-07:00";
     DateTime poo = DateTime.ParseExact(poop,"yyyy-MM-ddTHH:mm:ss.fffffffzzz",        
                                    System.Globalization.CultureInfo.InvariantCulture);
    

    In your case

     string sDate1=TextBox1.Text.ToString().Trim();
     string sDate2=TextBox1.Text.ToString().Trim();
    
     DateTime dt1= DateTime.ParseExact(sDate1,"MM-dd-yyyy",        
                                    System.Globalization.CultureInfo.InvariantCulture);
     DateTime dt2= DateTime.ParseExact(sDate2,"MM-dd-yyyy",        
                                    System.Globalization.CultureInfo.InvariantCulture);
    
     System.TimeSpan diffr =dt2 - dt1;
     Response.Write(diffr.Days);
    

    And it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been battling this for some time and I need some guidance. I'm
If anyone experienced with jPicker, I would really like some help on this. I
I would really like some advice here, to give some background info I am
I would really like to do something like this: Callable<MyObject> myCallable = .... Future<MyObject>
I know this isn't a programming question but I would really like the users
I know this isn't a straightforward question but I would really appreciate some feedback
I really need some guidance here as this issue is pretty confusing and extremely
Looking for some guidance on feasibility and implementation.. I would like to accomplish the
I would really like some advice on how to proceed with the following requirement.
I would really like to know how web sites decide what ad to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.