Possible Error in DateTime.mqh - Function CDateTime::DaysInMonth(void) const

 

Function always returns 0 

#include  <\Tools\DateTime.mqh>

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CDateTime CDt;
   int getint = Month();
   int dayinmonth = DaysInMonth(getint);
   Print ("Month int is: ",getint," Number of days in month is: ",dayinmonth);    
  }

Its possible that I am not doing this correctly.  

#include  <\Tools\DateTime.mqh>

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CDateTime CDt;
   int dayinmonth = DaysInMonth();
   Print ("Number of days in month is: ",dayinmonth); 
  }

Other function rely on this so could someone show me how its suppose to work?


I don't have a problem using the same code to generate the correct code. Just not with the function that is in the datetime lib.

#include  <\Tools\DateTime.mqh>

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CDateTime CDt;
   int getint = Month();
   int dayinmonth = DaysInMonth(getint);
   Print ("Month int is: ",getint," Number of days in month is: ",dayinmonth);    
  }
//+------------------------------------------------------------------+
int DaysInMonth(int mon) 

  {
   int leap_year;
   int year = Year();
//---
   switch(mon)
     {
      case  1:
      case  3:
      case  5:
      case  7:
      case  8:
      case 10:
      case 12:
         return(31);
      case  2:
         leap_year=year;
         if(year%100==0)
            leap_year/=100;
         return((leap_year%4==0)? 29 : 28);
      case  4:
      case  6:
      case  9:
      case 11:
         return(30);
     }
//---
   return(0);
  }
 
Diane Minshew:

Function always returns 0 

Its possible that I am not doing this correctly.  

Other function rely on this so could someone show me how its suppose to work?


I don't have a problem using the same code to generate the correct code. Just not with the function that is in the datetime lib.

It's interesting that you managed to compile through and run to see 0 as the result... I couldn't even compile... LOL

At least, not until I make these changes:

#include  <\Tools\DateTime.mqh>

void OnStart()
  {
//---
   CDateTime CDt;
   int getint = 4;//Month();
   CDt.DateTime(TimeLocal());
   int dayinmonth = CDt.DaysInMonth();
   Print ("Month int is: ",getint," Number of days in month is: ",dayinmonth);    
  }

and the result is 30.

 
Seng Joo Thio:

It's interesting that you managed to compile through and run to see 0 as the result... I couldn't even compile... LOL

At least, not until I make these changes:

and the result is 30.

So as long as the MqlDateTime struct is initiated it will be pushed to the function.. thank you.. 

 
Diane Minshew:

So as long as the MqlDateTime struct is initiated it will be pushed to the function.. thank you.. 

//Get Month output days in month 
//Change Month by increment and get new days of the month
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CDateTime CDt;   
   //CDt.DateTime(TimeLocal()); //Fills the TimeStruct
  
   /* IF REMOVED and the TIMESTUCT IS NOT FILLED 
      Output = 3000.12.05 00:59:59 
      The default DateTime is printed 
      https://www.mql5.com/en/docs/basis/types/integer/datetime
   */
  CDt.DateTime(TimeLocal()); 
  int dayinmonth = CDt.DaysInMonth();
  //Output the Data in DataTime TimeStuct
  Print("Current DateTime Object CDt : ",CDt.DateTime());
  Print("Current Number of Days in the month of the CDt Object",dayinmonth);
 
  CDt.MonInc(dayinmonth); //Only Modifies the Cdt Object
  int daysinmonth = CDt.DaysInMonth();
  Print("Modified DateTime Object CDt : ",CDt.DateTime());
  
  //CDt.DateTime is the Proof of the Object Change.
  Print("Modified Number of Days in the month of the CDt Object",daysinmonth);
  }
//+------------------------------------------------------------------+
Just in case anyone has interest... this is the code with comments of why..
 

Is it possible to change first day of the week?

I need to change Sunday to Saturday in meta5 to getting better info