Thread: Calculating Six months from any date

1. Calculating Six months from any date

Hi, can anyone help me with this. I need some way to calculate what date exatly would be six months from today so if I take todays date (4/11/2205) I'd expect it to return 5/5/2006.
This is a problem becuase of the number of days varying in each month...

2. Re: Calculating Six months from any date

See the help file for AddDateTime function

3. Re: Calculating Six months from any date

Dualtha,

Use the below function. It takes one parameter.

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[-] string GetDateDifference(integer iNumberOfDays)
[ ]
[ ] DATETIME DayAndTime
[ ] STRING sDate
[ ] // get current date and time
[ ] // format current date and time
[ ] sDate = FormatDateTime (DayAndTime, &quot;mm/dd/yyyy&quot
[ ] return sDate

main()
GetDateDifference(-600)</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

4. Re: Calculating Six months from any date

Thanks guys,

Patel does this guarantee that 6 months will be calculated independent of any particular day in any particular month?

5. Re: Calculating Six months from any date

The question is better directed at Segue [img]images/icons/smile.gif[/img]

6. Re: Calculating Six months from any date

If you are looking to add 6 months out as in Jan 3 to July 3, the best way to do this is to use GetDateTimePart and increment the month rather than trying to calculate the number of days in a 6 month period of time. Here's a way:

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[-] main ()
[ ] DATETIME dFirst = GetDateTime ()
[ ]
[ ] INTEGER iMonth = GetDateTimePart (dFirst, DTP_MONTH)
[ ] INTEGER iDay = GetDateTimePart (dFirst, DTP_DAY)
[ ] INTEGER iYear = GetDateTimePart (dFirst, DTP_YEAR)
[ ]
[ ] iMonth = iMonth + 6
[-] if iMonth &gt; 12
[ ] iMonth = iMonth-12
[ ] DATETIME dNewDate = MakeDateTime (iYear, iMonth, iDay)
[ ]
[ ] Print (dNewDate)</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

[ 11-07-2005, 02:21 PM: Message edited by: jamesso ]

7. Re: Calculating Six months from any date

Excellent Jamesso, was trying this and you saved me lots of time... Thanks

8. Re: Calculating Six months from any date

Cool, I was thinking more like when I want to know the correct date adding 123 days to January 3rd in a leap year.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:56 PM.