StructToTime

Convierte  una variable del tipo de estructura MqlDateTime a un valor del tipo datetime y devuelve el valor final.

datetime  StructToTime(
   MqlDateTime&  dt_struct      // estructura de fecha y hora
   );

Parámetros

dt_struct

[in]  Variable de estructura del tipo MqlDateTime.

Valor devuelto

Valor del tipo datetime que contiene la cantidad de segundos transcurridos desde 01.01.1970.

Ejemplo:

#property script_show_inputs
 
input int   InpYear  =  0;    // Year
input int   InpMonth =  0;    // Month
input int   InpDay   =  0;    // Day
input int   InpHour  =  0;    // Hour
input int   InpMin   =  0;    // Minutes
input int   InpSec   =  0;    // Seconds
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- corregimos los valores introducidos y los escribimos en las variables
   int year =  (InpYear<1970 ? 1970 : InpYear); // Si el año introducido es inferior a 1970, se utilizará 1970.
   int month=  (InpMonth<1 ?  1  :  InpMonth > 12  ?  12 :  InpMonth);
   int day  =  (InpDay  <1 ?  1  :  InpDay   > 31  ?  31 :  InpDay);
   int hour =  (InpHour <0 ?  0  :  InpHour  > 23  ?  23 :  InpHour);
   int min  =  (InpMin  <0 ?  0  :  InpMin   > 59  ?  59 :  InpMin);
   int sec  =  (InpSec  <0 ?  0  :  InpSec   > 59  ?  59 :  InpSec);
 
//--- mostramos los valores en el diario de registro
   PrintFormat("Entered date and time: %04u.%02u.%02u %02u:%02u:%02u"InpYearInpMonthInpDayInpHourInpMinInpSec);
   
//--- mostramos en el diario de registro los valores introducidos corregidos
   PrintFormat("Corrected date and time: %04u.%02u.%02u %02u:%02u:%02u"yearmonthdayhourminsec);
   
//--- escribir los valores de entrada en los campos correspondientes de la estructura
   MqlDateTime time_struct={};
   time_struct.yearyear;
   time_struct.mon = month;
   time_struct.day = day;
   time_struct.hourhour;
   time_struct.min = min;
   time_struct.sec = sec;
   
//--- convertimos la fecha y la hora de la estructura en una variable de tipo datetime y
   datetime time = StructToTime(time_struct);
   
//--- mostramos el resultado de la conversión de una variable de tipo de estructura MqlDateTime en un valor de tipo datetime
   Print("Converted date and time: ",TimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
   /*
  Resultados si introducimos valores por defecto cero:
   Entered date and time0000.00.00 00:00:00
   Corrected date and time1970.01.01 00:00:00
   Converted date and time1970.01.01 00:00:00
   
  resultados si introducimos un día de febrero-mes del año en curso incorrecto:
   Entered date and time2024.02.31 00:00:00
   Corrected date and time2024.02.31 00:00:00
   Converted date and time2024.03.02 00:00:00
   */
  }