Deconstruct date/time value into its component parts

// Deconstructs an Igor date/time value (seconds since 1904-01-01) into
// its component parts (year, month, dayOfMonth, etc.).
// Because it uses pass-by-reference parameters, this function can be called
// only from another user-defined function. See the Demo function below for usage.

Function DeconstructDate(dt, year, month, dayOfMonth, dayOfWeek, hour, minute, second)
    Variable dt                 // Input date/time value
    Variable& year              // Output
    Variable& month         // Output
    Variable& dayOfMonth        // Output
    Variable& dayOfWeek     // Output
    Variable& hour              // Output
    Variable& minute            // Output
    Variable& second            // Output
   
    String shortDateStr
   
    shortDateStr = Secs2Date(dt, -1)        // <day-of-month>/<month>/<year> (<day of week>)
   
    sscanf shortDateStr, "%d/%d/%d (%d)", dayOfMonth, month, year, dayOfWeek
   
    Variable time = mod(dt, 24*60*60)   // Get the time component of the date/time
   
    hour = trunc(time/(60*60))          // Get hour
    time -= hour * 60 * 60                  // Remove hour component
   
    minute = trunc(time/60)             // Get minute
    time -= minute * 60                 // Remove minute component
   
    second =  time 
End

Function Demo()
    Variable dt = datetime      // Right now
    Variable year, month, dayOfMonth, dayOfWeek, hour, minute, second
    DeconstructDate(dt, year, month, dayOfMonth, dayOfWeek, hour, minute, second)
    Printf "year=%d, month=%d, dayOfMonth=%d, hour=%d, minute=%d, second=%d\r", year, month, dayOfMonth, hour, minute, second
End

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More