|
ThatsMe. wrote: how can check number of days in a month are 28,29,30,or 31?
int GetNumberOfDays( int nYear, int nMonth )
{
COleDateTime objDate;
int nDay = 29;
for( ;nDay < 32; nDay++ )
{
objDate.SetDate( nYear, nMonth, nDay );
if( objDate.GetStatus() == COleDateTime::invalid )
{
break;
}
}
return --nDay;
}
|
|
|
|
|
Wouldn't this always return 31?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: Wouldn't this always return 31?
How? Can you explain?
|
|
|
|
|
if( objDate.GetStatus() == COleDateTime::invalid ) fails for some reason so the function always returns 31. I recall seeing this code somewhere in MSDN (??? probably). Used it some time back.
[modified]A quick look at MSDN gives me this:If you call GetStatus on a COleDateTime object constructed with the default, it will return valid
Eg:The status of this is 2000, 2, 31 = valid ???
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
modified on Wednesday, June 11, 2008 1:21 AM
|
|
|
|
|
_AnShUmAn_ wrote: If you call GetStatus on a COleDateTime object constructed with the default, it will return valid
But I am calling SetDate() after the construction of COleDateTime object. Suppose if you set a date as objDate.SetDate( 2008, 2, 30 ); The date will be invalid and if( objDate.GetStatus() == COleDateTime::invalid ) will return true.
|
|
|
|
|
I just tried this bit of code and it always returns me 31. even the parameters to the function when passed as 2000,2 returns 31. ??? Any reasons. I modified my last post to include this.
BTW does this code execute as expected at your end.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: BTW does this code execute as expected at your end.
yes. it returns 29.
Is it because of some OS environment problem ?I am running on windows XP with SP2.
|
|
|
|
|
Same here [WinXP SP2]. but it always returns 31. Will try and find the reason behind this behaviour and get back if possible.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Can any one else tell us whats the behavior in your machines??
|
|
|
|
|
It returns 29.
I have XP and SP2
Regards,
Sandip.
|
|
|
|
|
|
It returns 29,dont worry your code is correct.
|
|
|
|
|
|
BTW does your problem solve I think it was about threads,right?
|
|
|
|
|
Hamid. wrote: does your problem solve
That Delete file problem??nop. I failed to find a working solution.
Any way I updated my article. I have metioned the problem and have asked to tell me if any one finds some other solutions.
|
|
|
|
|
2 down votes . Seems some body doesn't like the idea.
|
|
|
|
|
Now see it again, its 3.3(dont forget our gold members ).
|
|
|
|
|
Hamid. wrote: Now see it again, its 3.3
Thanks Buddy..
|
|
|
|
|
Its 3.5 now
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Thanks BadKarma, So you does some Good-Karma's also, haaaa?
|
|
|
|
|
Yeah,
thats the Dark Side of me
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Should I repeat myself?
int daysOfMonth(int month, int year)
{
switch( month )
{
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
return year % 400 ? year % 100 ? year % 4 ? 28 : 29 : 28 : 29;
default:
return 31;
}
}
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Other code of your magic site,right?
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
There is an unjustified low-vote here[^]. I wish you were there.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|