Board index » Visual Studio » Bug in CDateTimeCtrl for 2 days only?

Bug in CDateTimeCtrl for 2 days only?

Visual Studio19
Our application is exhibiting a strange bug today out of the blue. The

CDateTimeCtrl is exhibiting a strange behavior. I have it set so that the

format is MMMM YYYY so we don't see the day. If it's set as a spin control

or if you use the arrows to inc/dec the month it doesn't show February. It

goes from January to <blank) then to March. By default it's populated with

today's date.



Jan 30 and Jan 31 cause problems. It's behaving like it think the month is

actually February where 30th and 31st don't exist.



Shouldn't the control automatically increment the day to a valid value when

changing month to February? It does this with other months where 31st isn't

valid. It must be a leap year bug?


-
 

Re:Bug in CDateTimeCtrl for 2 days only?

Clarification....



The issue isn't with February in particular. The issue occurs when the

format is set without the day, e.g. "MMMM yyyy"



When the day is not in the format the day increment fails because the day is

not dynamically changing.



Is this by design?





-

Re:Bug in CDateTimeCtrl for 2 days only?

If you are not setting the day for your control, then today it will default

to 30 which feb doesn't have, and then breaks things.



So do this to fix it:



COleDateTime CurTime = COleDateTime::GetCurrentTime();

COleDateTime Time(CurTime.GetYear(),CurTime.GetMonth(),1,12,0,0);

m_DateTimeCtrl.SetTime(Time);

m_DateTimeCtrl.SetFormat("MMMM yyyy");





AliR.





"Eric Margheim" <nospam***ericm@charter.net>wrote in message

Quote
Our application is exhibiting a strange bug today out of the blue. The

CDateTimeCtrl is exhibiting a strange behavior. I have it set so that

the format is MMMM YYYY so we don't see the day. If it's set as a spin

control or if you use the arrows to inc/dec the month it doesn't show

February. It goes from January to <blank) then to March. By default it's

populated with today's date.



Jan 30 and Jan 31 cause problems. It's behaving like it think the month

is actually February where 30th and 31st don't exist.



Shouldn't the control automatically increment the day to a valid value

when changing month to February? It does this with other months where

31st isn't valid. It must be a leap year bug?







-

Re:Bug in CDateTimeCtrl for 2 days only?

I just read your entire post, seem like a leap year bug. Because when I set

my computers date to Jan 30 2007 and ran the program without modifing the

date in my CDateTimeCtrl it worked fine!



Ali





"AliR (VC++ MVP)" <AliR@online.nospam>wrote in message

Quote
If you are not setting the day for your control, then today it will

default to 30 which feb doesn't have, and then breaks things.



So do this to fix it:



COleDateTime CurTime = COleDateTime::GetCurrentTime();

COleDateTime Time(CurTime.GetYear(),CurTime.GetMonth(),1,12,0,0);

m_DateTimeCtrl.SetTime(Time);

m_DateTimeCtrl.SetFormat("MMMM yyyy");





AliR.





"Eric Margheim" <nospam***ericm@charter.net>wrote in message

news:eFSM%23u3YIHA.4160@TK2MSFTNGP03.phx.gbl...

>Our application is exhibiting a strange bug today out of the blue. The

>CDateTimeCtrl is exhibiting a strange behavior. I have it set so that

>the format is MMMM YYYY so we don't see the day. If it's set as a spin

>control or if you use the arrows to inc/dec the month it doesn't show

>February. It goes from January to <blank) then to March. By default

>it's populated with today's date.

>

>Jan 30 and Jan 31 cause problems. It's behaving like it think the month

>is actually February where 30th and 31st don't exist.

>

>Shouldn't the control automatically increment the day to a valid value

>when changing month to February? It does this with other months where

>31st isn't valid. It must be a leap year bug?

>









-

Re:Bug in CDateTimeCtrl for 2 days only?



"AliR (VC++ MVP)" <AliR@online.nospam>wrote in message

Quote
I just read your entire post, seem like a leap year bug. Because when I

set my computers date to Jan 30 2007 and ran the program without modifing

the date in my CDateTimeCtrl it worked fine!







I don't thinks it's a leap year bug. It's not only an issue with February.

I can make it happen when I set my system time to Jan 31 2007 instead of

2008.



You can duplicate the same behavior by setting your system time to March

31st then incrementing to April or August 31st then incrementing to

September.



The bug appears to be that the day does not automatically adjust to a valid

last-day-of-month when the format does not include the day, e.g. "MMMM yyyy"





-