15,797,721 members
See more:
I want to take a difference between two date and convert it into the date
like in 10/28/2010 add 7 days so the next date is 11/04/2010 so how to calculate the date ?

I mean that if a month at the End and we select the 29th if I add 8 so the result 36 but 36 is not possible date.

Next Que.

how to calculate the quarter of the year from the starting date to Next Date like first Quarter is Start from April to Aug. so the first date of quarter and the Last Date of Quarter

Posted
Updated 22-Oct-10 19:27pm
v3
Rajesh Anuhya 22-Oct-10 8:12am
your question is not clear for me, how the two dates difference become a Date???
shakil0304003 22-Oct-10 12:10pm
what is your requirement? days difference between two date!!! Or add 7/some days to a date? Clear it?
Mohd Wasif 23-Oct-10 1:23am
Let me know whether u r working with sql server 2005 or with asp.net
Bikash Shrestha From Nepal 23-Oct-10 2:02am

## Solution 4

To calculate the quarter you can use the Time Period Library for .NET:
C#
```// ----------------------------------------------------------------------
public static void ShowQuarterInfo()
{
ShowQuarterInfo( DateTime.Now );
} // ShowQuarterInfo

// ----------------------------------------------------------------------
public static void ShowQuarterInfo( DateTime moment )
{
// working quarter
Quarter quarter = new Quarter( moment );
Console.WriteLine( "Quarter start: " + quarter.FirstDayStart );
Console.WriteLine( "Quarter end: " + quarter.LastDayStart );

// previous quarter
Quarter previousQuarter = quarter.GetPreviousQuarter();
Console.WriteLine( "Previous Quarter start: " + previousQuarter.FirstDayStart );
Console.WriteLine( "Previous Quarter end: " + previousQuarter.LastDayStart );

// next quarter
Quarter nextQuarter = quarter.GetNextQuarter();
Console.WriteLine( "Next Quarter start: " + nextQuarter.FirstDayStart );
Console.WriteLine( "Next Quarter end: " + nextQuarter.LastDayStart );
} // ShowQuarterInfo```

You will find more samples in the article Time Period Library for .NET[^].

Cheers, Jani.

Jani Giannoudis 18-Mar-11 19:23pm

## Solution 1

Use `AddDays `Like

`DateTime mydt = DateTime.Today.Date.AddDays(7);`

Abhinav S 22-Oct-10 8:50am

## Solution 3

Dear,

U can't make the difference between two dates in date form.
but u can get date difference in sec,min,hr,days,months,years.
So In order to get difference b/n two dates we need to do concatenation,but the things is this if we take difference of same day,same month and same year then we will not date in date form coz in each case we will get 0 for days,months and years.That will look like 00\00\0000. Any thing can be zero as per your choice.So if we add 7 days then we will not get proper result

E.G
this gives 1900-01-07 00:00:00.000
coz
select datediff(d,getdate(),getdate()+1)
it gives 1.
if we add 7 days then we will get
1900-01-07

## Solution 2

Your requirement -> "I want to take a difference between two date and convert it into the date". And it's solution ->
```DateTime d1 = new DateTime(2010, 10, 28);
DateTime d2 = new DateTime(2010,11,04);
TimeSpan p1 = d2.Subtract(d1);
MessageBox.Show(p1.Days.ToString());```

William Winner 22-Oct-10 12:13pm
While his original question was unclear, I think it was clear that he was saying, he wants to take a date and add a number of days to the first date and get the second date.

"like in 10/28/2010 add 7 days so the next date is 11/04/2010"
shakil0304003 22-Oct-10 12:26pm
If your say is right, then why he said "I want to take a difference between two date and convert it into the date". Explain why he said like this?
William Winner 22-Oct-10 13:17pm
probably because English isn't his first language...

Aside from that, you chose to answer when an answer had already been given (and most likely already been marked as the solution). And I think from the tone of your answer that you were just trying to make the point that he didn't phrase his question properly.