StructToTime

MqlDateTime yapısındaki bir değişkeni datetime tipli bir değere dönüştürür ve sonuç değerine dönüş yapar .

datetime  StructToTime(
   MqlDateTime&  dt_struct      // tarih ve zaman yapısı
   );

Parametreler

dt_struct

[in] MqlDateTime yapı tipli bir değişken.

Dönüş değeri

01.01.1970'den beri geçen saniyeler şeklinde datetime tipi bir değer.

Örnek:

#property script_show_inputs
 
input int   InpYear  =  0;    // Yıl
input int   InpMonth =  0;    // Ay
input int   InpDay   =  0;    // Gün
input int   InpHour  =  0;    // Saat
input int   InpMin   =  0;    // Dakika
input int   InpSec   =  0;    // Saniye
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- girilen değerleri ayarla ve değişkenlere yaz
   int year =  (InpYear<1970 ? 1970 : InpYear); // girilen yıl 1970'den küçükse, 1970 kullanılır
   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);
 
//--- girilen değerleri günlükte görüntüle
   PrintFormat("Entered date and time: %04u.%02u.%02u %02u:%02u:%02u"InpYearInpMonthInpDayInpHourInpMinInpSec);
   
//--- düzeltilmiş girilen değerleri günlükte görüntüle
   PrintFormat("Corrected date and time: %04u.%02u.%02u %02u:%02u:%02u"yearmonthdayhourminsec);
   
//--- girdi değerlerini ilgili yapı alanlarına yaz
   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;
   
//--- yapıdaki tarih ve saati datetime türünde bir değişkene dönüştür ve
   datetime time = StructToTime(time_struct);
   
//--- MqlDateTime yapı türündeki değişkenden datetime türünde bir değere dönüştürme sonucunu görüntüle
   Print("Converted date and time: ",TimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
  /*
  Sıfır varsayılan değeri girilirse sonuçlar:
   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
   
  mevcut yılın şubat ayına ait yanlış bir gün girilirse sonuçlar:
   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
  */
  }