Click here to Skip to main content
15,892,674 members
Home / Discussions / C#
   

C#

 
AnswerRe: passing data between forms Pin
OriginalGriff31-Aug-12 9:21
mveOriginalGriff31-Aug-12 9:21 
GeneralRe: passing data between forms Pin
mamoony31-Aug-12 10:08
mamoony31-Aug-12 10:08 
GeneralRe: passing data between forms Pin
OriginalGriff31-Aug-12 21:09
mveOriginalGriff31-Aug-12 21:09 
GeneralRe: passing data between forms Pin
BillWoodruff3-Sep-12 15:59
professionalBillWoodruff3-Sep-12 15:59 
GeneralRe: passing data between forms Pin
mamoony10-Sep-12 10:06
mamoony10-Sep-12 10:06 
QuestionDelete From XML File Pin
Kevin Marois31-Aug-12 8:47
professionalKevin Marois31-Aug-12 8:47 
AnswerRe: Delete From XML File Pin
PIEBALDconsult31-Aug-12 9:40
mvePIEBALDconsult31-Aug-12 9:40 
GeneralRe: Delete From XML File Pin
Kevin Marois31-Aug-12 9:52
professionalKevin Marois31-Aug-12 9:52 
GeneralRe: Delete From XML File Pin
PIEBALDconsult31-Aug-12 11:20
mvePIEBALDconsult31-Aug-12 11:20 
GeneralRe: Delete From XML File Pin
AmitGajjar31-Aug-12 23:27
professionalAmitGajjar31-Aug-12 23:27 
QuestionTo show the properties page of a file and navigate to a tab Pin
John T.Emmatty31-Aug-12 4:03
John T.Emmatty31-Aug-12 4:03 
AnswerRe: To show the properties page of a file and navigate to a tab Pin
Shameel31-Aug-12 4:56
professionalShameel31-Aug-12 4:56 
GeneralRe: To show the properties page of a file and navigate to a tab Pin
John T.Emmatty31-Aug-12 5:08
John T.Emmatty31-Aug-12 5:08 
AnswerRe: To show the properties page of a file and navigate to a tab Pin
Shameel31-Aug-12 5:11
professionalShameel31-Aug-12 5:11 
Question.Net C# GUI dll will use in VB6 (Not user control) Pin
mamoony31-Aug-12 3:52
mamoony31-Aug-12 3:52 
AnswerRe: .Net C# GUI dll will use in VB6 (Not user control) Pin
Shameel31-Aug-12 4:47
professionalShameel31-Aug-12 4:47 
GeneralRe: .Net C# GUI dll will use in VB6 (Not user control) Pin
mamoony31-Aug-12 7:59
mamoony31-Aug-12 7:59 
Questionhow to get difference between 2 dates in years:months format? Pin
Anurag Sinha V30-Aug-12 21:56
Anurag Sinha V30-Aug-12 21:56 
Hi all,
AM working on a C# project..
my requirement is as follows:
there are 2 dates viz date1 & date2.
if date1 > date2
the difference should come as e.g (3years,2months)
if date1 < date2
the difference should come as e.g (-3years,-2months)
I am able to get the first scenario but the second scenario I am having problems with, not able to calculate the number of months in negative quite correctly...
Below is the code used in case of positive scenario,currentdate is alwys greater than the assetCapDate passed as a value:

public string newmethod(string assetCapDate)
{

string timeStr = string.Empty;
int years = 0;
int months = 0;
int days = 0;
TimeSpan ts = new TimeSpan();
System.DateTime date1 = DateTime.Now;
System.DateTime date2 = Convert.ToDateTime(assetCapDate);
ts = date1.Subtract(date2);
years = (ts.Days/365);
do
{
for(int i=0; i <= 12; i++)
{
if(date1.Subtract(date2.AddYears(years).AddMonths(i)).Days >=0)
{
months = i;
}
else
{
break;
}
}

if(months > 12)
years = years + 1;
}while(months > 12);

days = date1.Subtract(date2.AddYears(years).AddMonths(months)).Days;

if (years > 0)
{
timeStr += years.ToString() + " Years, ";
}
if (months > 0)
{
timeStr += months.ToString() + " Months";
}

if (days > 0)
{
timeStr += days.ToString() + " Days";
}

return(timeStr);
}


Any help would be highly appreciated.

I am not sure whether this question falls under C# domain..Moderators please advise accordingly..will move this question to another domain if required.
Regards
Anurag

AnswerRe: how to get difference between 2 dates in years:months format? Pin
Richard MacCutchan30-Aug-12 22:36
mveRichard MacCutchan30-Aug-12 22:36 
GeneralRe: how to get difference between 2 dates in years:months format? Pin
Anurag Sinha V30-Aug-12 23:29
Anurag Sinha V30-Aug-12 23:29 
GeneralRe: how to get difference between 2 dates in years:months format? Pin
Richard MacCutchan31-Aug-12 4:11
mveRichard MacCutchan31-Aug-12 4:11 
AnswerRe: how to get difference between 2 dates in years:months format? Pin
PIEBALDconsult31-Aug-12 3:17
mvePIEBALDconsult31-Aug-12 3:17 
GeneralRe: how to get difference between 2 dates in years:months format? Pin
Marcus_231-Aug-12 3:49
Marcus_231-Aug-12 3:49 
AnswerRe: how to get difference between 2 dates in years:months format? Pin
Ravi Bhavnani31-Aug-12 7:21
professionalRavi Bhavnani31-Aug-12 7:21 
GeneralRe: how to get difference between 2 dates in years:months format? Pin
Anurag Sinha V31-Aug-12 18:08
Anurag Sinha V31-Aug-12 18:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.