Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: how to get difference between 2 dates in years:months format? Pin
timeArrowI2-Sep-12 21:59
timeArrowI2-Sep-12 21:59 
GeneralRe: how to get difference between 2 dates in years:months format? Pin
Anurag Sinha V3-Sep-12 1:00
Anurag Sinha V3-Sep-12 1:00 
QuestionTrackbar's Scroll Box Position Pin
varunpandeyengg30-Aug-12 20:57
varunpandeyengg30-Aug-12 20:57 
AnswerRe: Trackbar's Scroll Box Position Pin
OriginalGriff30-Aug-12 21:11
mveOriginalGriff30-Aug-12 21:11 
QuestionDrawLines problem Pin
john563230-Aug-12 20:42
john563230-Aug-12 20:42 
AnswerRe: DrawLines problem Pin
Abhinav S30-Aug-12 21:08
Abhinav S30-Aug-12 21:08 
AnswerRe: DrawLines problem Pin
Manfred Rudolf Bihy30-Aug-12 21:12
professionalManfred Rudolf Bihy30-Aug-12 21:12 
AnswerRe: DrawLines problem Pin
OriginalGriff30-Aug-12 21:23
mveOriginalGriff30-Aug-12 21:23 
AnswerRe: DrawLines problem Pin
Dave Kreskowiak31-Aug-12 2:13
mveDave Kreskowiak31-Aug-12 2:13 
QuestionC# workin with xsd file Pin
dcof30-Aug-12 18:04
dcof30-Aug-12 18:04 

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.