Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to add 6 months to a date?
How to add 6 months to a date? [message #36699] Tue, 26 June 2012 19:21 Go to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hello!
I'm trying to understand U++ Date type and how to do arithmetic with it.
How can I add 6 months to a date? Can you give me a short example?

Thanks
Re: How to add 6 months to a date? [message #36701 is a reply to message #36699] Tue, 26 June 2012 21:50 Go to previous messageGo to next message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi Lectus,

Perhaps you can try this link

http://www.ultimatepp.org/examples$Days$en-us.html

The code example shows how to calculate the number of days between 2 dates. So you can transpose to add 6 months to a given date.

Hope this is helpful
____________________________
Cheers

Biobytes
Re: How to add 6 months to a date? [message #36702 is a reply to message #36701] Tue, 26 June 2012 22:34 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Thanks.

I was playing with U++ Date type and editdate and calendar controls and realized U++ is smart enough to know when a month has 28 or 30 or 31 days.

For example, what I expected I get with the code below:
Date d = cal1.GetDate(); //read date
	d += (30 * 6); // add 6 months: 30 days * 6
	cal2.SetDate(d); // write to the other calendar


That's the behavior I wanted.
Re: How to add 6 months to a date? [message #36725 is a reply to message #36702] Fri, 29 June 2012 09:05 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
lectus wrote on Tue, 26 June 2012 16:34

Thanks.

I was playing with U++ Date type and editdate and calendar controls and realized U++ is smart enough to know when a month has 28 or 30 or 31 days.



Not correct. Use:

Date AddMonths(Date date, int months);
Date AddYears(Date date, int years);

Mirek
Previous Topic: [Solved]XML Rpc client will halt when server is not running
Next Topic: GetTimeZoneText() warning
Goto Forum:
  


Current Time: Fri Apr 19 10:37:40 CEST 2024

Total time taken to generate the page: 0.02062 seconds