Hi All,

My application requires lot of Date formatting calculations.
Here is mynew issue, which i am trying for last two days.
Hope someone can help me in this

I have startDate as First date of current month
endDate as todays date.

eg: 2/1/2007 ---- 2/19/2007

Now what I want to calculate 3/10/2007 and 1/12/2007 from this data.
That is I want to calculate 2/19/2007 + (difference of 2/19/2007 and 2/1/2007)
2/1/2007 - (difference of 2/19/2007 and 2/1/2007)

Hope I am not confusing you.

Thanks

Recommended Answers

All 4 Replies

Kind of confused...

Let's simplify this a little bit by assigning variable names to each date.

A = 2/1/2007 (First day of current month)
B = 2/19/2007 (Current date)
C = 3/10/2007 (Some future date)
D = 1/12/2007 (Some past date)

Do the parenthese describe your requirements?

Now, what are you trying to calculate and what do you expect as a result. When I say result, I mean - are you expecting a date. Are you expecting a difference such as number of days, hours, minutes etc...

And what programming language is your preferred choice? VB.Net, C#, Javascript, etc.

I am sorry.
I tried to explain my problem, but seems you all didnt get what I meant
hmmm.. I have to little bit more explain

Exactly, you assumed is correct.
I want to display the date. 3/10/07
and 1/12/2007

Not the difference in days
Any ideas????

Sorry for the confusion

A = 2/1/2007 (First day of current month)
B = 2/19/2007 (Current date)
C = 3/10/2007 (Some future date)
D = 1/12/2007 (Some past date)

You want to know how to calculate the following right?

B + (B-A) = C (This actually gives me 3/9/2007)
A - (B-A) = D (This actually gives me 1/14/2007)

Here's some code in C#. I hope this helps.

using System;
using System.Collections.Generic;
using System.Text;
namespace Test {
  class Program {
    static void Main(string[] args) {
    DateTime A = new DateTime(2007, 2, 1);
    DateTime B = new DateTime(2007, 2, 19);
    //B = DateTime.Now; // Use this to calculate from current date
    DateTime C, D;
    TimeSpan DiffBminusA = (B - A);
    C = B.AddDays(DiffBminusA.Days);
    D = A.AddDays(-DiffBminusA.Days);
    Console.Write(
      "\n\n\nA==" + A.ToString()
      + "\nB==" + B.ToString()
      + "\nDiffBminusA==" + DiffBminusA.ToString()
      + "\nDiffBminusA.Days==" + DiffBminusA.Days.ToString()
      + "\nC==" + C.ToString()
      + "\nD==" + D.ToString() + "\n\n\n");
    }
  }
}

thanks
Hope this will solve my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.