473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

months between two dates

hi,

I want to calculate tne months between two dates.Actually i am using Asp.net2.0.Is it possible to calculate using Sql or Asp,net..I want to list the months betweeen two dates.Help me...
Jun 23 '07 #1
10 2534
kenobewan
4,871 Expert 4TB
What format are your dates in?
Jun 24 '07 #2
Date is in the format of (MM/DD/YYYY).i want to list the months..
Jun 25 '07 #3
kenobewan
4,871 Expert 4TB
One way would be to calculate the difference in numbers and then have the month names in an arraylist. HTH.
Jun 25 '07 #4
hi,

I want to display the months between dates

for ex.If i give a 2 dates such as 04/05/2006 and 04/05/2007

the result would be April,may,june..........March

plz help me..very very urgent..
Jun 26 '07 #5
plz tel me the syntax and how to do it..
Jun 26 '07 #6
kenobewan
4,871 Expert 4TB
Multiple posting is against site rules. Please read the faqs. Thanks.

MODERATOR
Jun 26 '07 #7
kenobewan
4,871 Expert 4TB
Suggest you have a go and report back.
Jun 26 '07 #8
sorry.. I wont repeat it..
Jun 26 '07 #9
Hi,

There is no direct way (at least to my knowledge). Write a custome function to get the array. I think you might have months for 2 years (wht wud u do then?)
I'm assuming that u need it for any number of years.
Algorithm: (In steps)
1. Write a function to return string array (or list for binding).
2. Create private string array internally from 0 to 11 index (Jan to Dec).
3. Accept two dates as parameters.
4. Now, the logic needs to take care the way u want the difference.
4.1 Just take month from smaller date and loop (twice) to reach to thye month in bigger date. OR
4.2 Take difference between the dates as timespan, then take TotalMonths from it and loop using mod ("%") to fill whole list.

5. Return the array (or list)

If I get some more time today, I'll write some code for you.

Cheers,
Nik
Jun 26 '07 #10
private int CalculateMonthDifference(DateTime startDate, DateTime endDate)
{
int diff = 0;

while(startDate <= endDate)
{
endDate = endDate.AddMonths(-1);
diff++;
}
if (diff == 0)
{
return diff;
}
else
{
return diff -1;
}
}


This will loop through and give the number of months difference by subtracting 1 month from the end date until it less than the start date. Ok its not elegent but it works and the number of loops is not massive (e.g. 10 years diff would be 1200 loops which on todays machines is nothing)
Jul 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: sandy | last post by:
Hi, Using Java script I am trying to create code where when you place in the start date it automatically calculates 6 months for the experations date. For example when I place 01/01/04 as the...
7
by: bryanilton | last post by:
I was hoping someone could help me with this.. I'm not very familiar with javascript but I'm pretty sure it can help me with what I need to accomplish. I've tried piecing several pieces of script...
6
by: carl.barrett | last post by:
Hi, I have a continuous form based on a query ( I will also be creating a report based on the same query). There are 2 fields: Date Obtained and Date Of Expiry I want a further 3 columns...
5
by: Juan | last post by:
Hi everyone, is there a function that calculates the exact amount of Years, Months, and Days between two days? TimeDiff is not good enough, since it calculates, for example: Date 1: Dec....
9
by: Robin Tucker | last post by:
Hiya, I need to test "relative dates" in my program, such as "last six months" or "last 3 months" or "in the last week" etc. How can I do this with a DateTime structure? ie. If NodeDate...
2
by: bufbec | last post by:
I have worked on this for hours and can't come up with a solution. Hope someone can help me. I have a table called TMBS_HMAUDIT_PARMS. this table contains data to tell me how often a person is...
6
by: Sridhar | last post by:
Hi, I need to display a calendar that shows all the months of an year. In that, I need to show different colors for certain events. I know how to display a calendar for a certain month but I am...
14
by: jpr | last post by:
Friends, I have a form with four fields, date1, date2, date3 and date4. All these have all a mm/dd/yyyy format and have their source to a table. I need to add an unbound control (I will name...
5
by: wespw1 | last post by:
I have a form where I have 2 dates: 06/27/2007 01/28/1996 What I need to get is the difference between the 2 dates in months. Or in otherwords I am trying to get the age of the 2 dates in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.