Date Formatting Calculations!!!

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Date Formatting Calculations!!!

 
0
  #1
Feb 19th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

Re: Date Formatting Calculations!!!

 
0
  #2
Feb 19th, 2007
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.
-Mike
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: Date Formatting Calculations!!!

 
0
  #3
Feb 19th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

Re: Date Formatting Calculations!!!

 
0
  #4
Feb 19th, 2007
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.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Test {
  5. class Program {
  6. static void Main(string[] args) {
  7. DateTime A = new DateTime(2007, 2, 1);
  8. DateTime B = new DateTime(2007, 2, 19);
  9. //B = DateTime.Now; // Use this to calculate from current date
  10. DateTime C, D;
  11. TimeSpan DiffBminusA = (B - A);
  12. C = B.AddDays(DiffBminusA.Days);
  13. D = A.AddDays(-DiffBminusA.Days);
  14. Console.Write(
  15. "\n\n\nA==" + A.ToString()
  16. + "\nB==" + B.ToString()
  17. + "\nDiffBminusA==" + DiffBminusA.ToString()
  18. + "\nDiffBminusA.Days==" + DiffBminusA.Days.ToString()
  19. + "\nC==" + C.ToString()
  20. + "\nD==" + D.ToString() + "\n\n\n");
  21. }
  22. }
  23. }
-Mike
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: Date Formatting Calculations!!!

 
0
  #5
Feb 19th, 2007
thanks
Hope this will solve my problem
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum


Views: 2359 | Replies: 4
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC