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...
10 2534
What format are your dates in?
Date is in the format of (MM/DD/YYYY).i want to list the months..
One way would be to calculate the difference in numbers and then have the month names in an arraylist. HTH.
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..
plz tel me the syntax and how to do it..
Multiple posting is against site rules. Please read the faqs. Thanks.
MODERATOR
Suggest you have a go and report back.
sorry.. I wont repeat it..
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
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)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |