StrToTime

 

Dear Metaquote Users,

My codes are below:

string ExpiredDate1 = GetExpireDateFromServer(tanggal, Your_Id);    
PrintFormat("FROM SERVER : %s", ExpiredDate1); 

....
PrintFormat("AFTER SPLIT : %s", ExpiredDate); 
StringReplace(ExpiredDate,"-",".");     
PrintFormat("AFTER REPLACE : %s", ExpiredDate); 
datetime d1=StrToTime(ExpiredDate);
PrintFormat("Expire : %d - %s",d1, TimeToStr(d1,TIME_DATE|TIME_SECONDS));
datetime d2=TimeCurrent();
PrintFormat("Now : %d - %s",d2, TimeToStr(d2,TIME_DATE|TIME_SECONDS));


The outputs are :

Now : 1423911592 - 2015.02.14 00:00:00
Expire : 1423872000 - 2015.02.14 00:00:00
AFTER REPLACE : 2015.05.07
AFTER SPLIT : 2015-05-07
FROM SERVER : 2015-05-07

I search, where are the mistakes in RED TYPE (StrToTime  function) that return wrong date value?  The integer value of datetime is different, but TimeToStr give the same value.

Thx.

 


 
That's seems weird, are you sure it's the real code executed to produce this output ?
 

You haven't posted the code for when ExpiredDate1 becomes ExpiredDate (the "AFTER SPLIT" bit).

Substituting "2015-05-07" for GetExpireDateFromServer(tanggal, Your_Id) and ignoring the AFTER SPLIT (can't see the code), everything behaves as it should:

//string ExpiredDate1 = GetExpireDateFromServer(tanggal, Your_Id);    
string ExpiredDate = "2015-05-07";    
PrintFormat("FROM SERVER : %s", ExpiredDate); 
PrintFormat("AFTER SPLIT : %s", ExpiredDate); 
StringReplace(ExpiredDate,"-",".");     
PrintFormat("AFTER REPLACE : %s", ExpiredDate); 
datetime d1=StrToTime(ExpiredDate);
PrintFormat("Expire : %d - %s",d1, TimeToStr(d1,TIME_DATE|TIME_SECONDS));
datetime d2=TimeCurrent();
PrintFormat("Now : %d - %s",d2, TimeToStr(d2,TIME_DATE|TIME_SECONDS));

  

 
Thx for the replies.

Yes, if we hardcoded :

string ExpiredDate = "2015-05-07";

 It will get the true value of date. But this value was get from external function

string ExpiredDate1 = GetExpireDateFromServer(tanggal, Your_Id); 

 I only split  : ExpiredDate1 to ExpiredDate and as we see the true value from server.

 The complete codes are below :

if(clickedChartObject==DRAWUI_ACTIVATE || clickedChartObject==DRAWUI_ACTTITLE)
      {
        
         int year = TimeYear(iTime(Symbol(),0,0));
         int month = TimeMonth(iTime(Symbol(),0,0)); 
         int date = TimeDay(iTime(Symbol(),0,0)); 
         
         if(year<=0)
            year=2000;
         if(month<=0)
            month=1;
         if(date<=0)
            date=1;
      
         string tanggal = "2014-1-1";
         tanggal = year + "-" + month + "-" + date;     
         string ExpiredDate1 = GetExpireDateFromServer(tanggal, Your_Id);    
         PrintFormat("FROM SERVER : %s", ExpiredDate1); 
         string sep=":";                
         ushort u_sep;                  
         string result[];               
         u_sep=StringGetCharacter(sep,0);
         int k=StringSplit(ExpiredDate1,u_sep,result);
         int size=ArraySize(result);
        
         string expired="";
         if(size>1)
         {
            expired = result[0];
            IsExpired = 1;  
            ExpiredDate = result[1];   
            StringReplace(ExpiredDate,"-",".");          
            ObjectSetString(0,DRAWUI_ACTTITLE,OBJPROP_TEXT,ExpiredDate);   
                        
         }else
         {
            if(size>0)
            {
               ExpiredDate = result[0];  
               PrintFormat("AFTER SPLIT : %s", ExpiredDate); 
               StringReplace(ExpiredDate,"-",".");     
               PrintFormat("AFTER REPLACE : %s", ExpiredDate); 
               datetime d1=StrToTime(ExpiredDate);
               PrintFormat("Expire : %d - %s",d1, TimeToStr(d1,TIME_DATE|TIME_SECONDS));
               datetime d2=TimeCurrent();
               PrintFormat("Now : %d - %s",d2, TimeToStr(d2,TIME_DATE|TIME_SECONDS));
               if(d1>d2)
                  IsExpired = 0;  
               else
                  IsExpired = 1;          
               ObjectSetString(0,DRAWUI_ACTTITLE,OBJPROP_TEXT,ExpiredDate);                
            }
         }   
         
         string handle = CreateExpiredDateToRegistry(Enkripsi(ExpiredDate1), Enkripsi(Your_Id));
         
         if(handle !="")
           PrintFormat("%s",handle);
      }

 Thx.

 

Finally I use MqlDateTime (StructToTime) to construct time. Not using StrToTime. And everything is runing well.

 

         ExpiredDate = result[0];  

         string sep1="-";                
         ushort u_sep1;                  
         string result1[];               
         u_sep1=StringGetCharacter(sep1,0);
         int k1=StringSplit(ExpiredDate,u_sep1,result1);
         int size1=ArraySize(result1);         
         
         MqlDateTime  dt_struct;
         if(size1>0)
            dt_struct.year = result1[0];
         if(size1>1)
            dt_struct.mon = result1[1];
         if(size1>2)
            dt_struct.day = result1[2];
        
         datetime d1 =  StructToTime(dt_struct);

 

 Thx.