Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Raj.Trivedi
More...


Forums » .NET » ASP.NET »

Difference off two date fields need to display when gridviewloaded


Posted Date: 18 Aug 2012      Posted By:: roshancom     Member Level: Silver    Member Rank: 1077     Points: 4   Responses: 1



i have two javascript calender field in my webpage



date A : From 1/4/2012 to 18/7/2012 (total months 4)

date B : From 1/4/2012 to 18/9/2012 (total months 6) difference(6-4=2)





i have a serch optin in this page and some details vil display on gridview regarding this date.

My need is one of the field in grid view is for differece of this months....


How can i display this difference in my grid view after click on the search button




Responses

#684682    Author: Devaraj T N      Member Level: Gold      Member Rank: 18     Date: 18/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

HI,

In search button click event you have to find the difference between date A and date B and update the difference to the database column after that you can fetch the data from database and bind it into gridview.

For an example,

//date A

//first date of date A which is indian format convert into into US format like below
string firstdate = "1/4/2012";
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
String datetime = firstdate;
DateTime fristdt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

//second date of date A
string secondate = "18/7/2012";
IFormatProvider secprovider = new System.Globalization.CultureInfo("en-CA", true);
String secdatetime = secondate;
DateTime secdt = DateTime.Parse(secdatetime, secprovider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

//difference of date A
TimeSpan diffdta = secdt.Subtract(fristdt);

//Next is date B again you have to convert into US format


//first date of date B which is indian format convert into into US format like below
string firstdateb = "1/4/2012";
IFormatProvider providerb = new System.Globalization.CultureInfo("en-CA", true);
String datetimeb = firstdateb;
DateTime fristdtb = DateTime.Parse(datetimeb, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

//second date of date B which is in indian format should be converted into US format
string secondateb = "18/9/2012";
IFormatProvider secproviderb = new System.Globalization.CultureInfo("en-CA", true);
String secdatetimeb = secondateb;
DateTime secdtb = DateTime.Parse(secdatetimeb, secproviderb, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

//difference of date A
TimeSpan diffdtb = secdtb.Subtract(fristdt);

//finally we can find the difference between two dates date A and date B timespan by subtracting diffdta from diffdtb
TimeSpan totaldiff = diffdtb - diffdta;

//Now conver timespan to months by multiplying totaldiff 365 and divided by 30
int months = (totaldiff.Days % 365) / 30;

months value should be updated into database column and fetch this data and bind it into gridview.


Regards,
Devaraj T.N
Senior Software Engineer,
Microsoft Certified Technology Specialist.

Regards,
T.N. THEAAVARAAJ
Senior Software Engineer,
Microsoft Certified Technology Specialist.
Email:devabe2005@gmail.com



 
Post Reply
You must Sign In to post a response.

Next : List problem in asp.net
Previous : Convert a HTML Control (Div or Table) to an image using C#/ or JavaScript or J query
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.