Create a Date/Time Wave from Text Waves

// Creates a date/time wave from a date wave stored as text in YYYY-MM-DD format
// and a time wave stored as text in HH:MM:YY format.
// Example:
//      Make/O/T wDateAsText = {"2016-08-15", "2016-08-15"}
//      Make/O/T wTimeAsText = {"19:01:00", "19:01:18"}
//      TextWavesToDateTimeWave(wDateAsText, wTimeAsText, "wDateTime")
//      Edit wDateTime

Function ConvertTextToDateTime(dateAsText, timeAsText)
    String dateAsText       // Assumed in YYYY-MM-DD format
    String timeAsText       // Assumed in HH:MM:DD format
   
    Variable dt
    Variable year, month, day
    sscanf dateAsText, "%d-%d-%d", year, month, day
    dt = Date2Secs(year, month, day)
   
    Variable timeOfDay
    Variable hour, minute, second
    sscanf timeAsText, "%d:%d:%d", hour, minute, second
    timeOfDay = 3600*hour + 60*minute + second
   
    dt += timeOfDay
   
    return dt
End

Function/WAVE TextWavesToDateTimeWave(dateAsTextWave, timeAsTextWave, outputWaveName)
    WAVE/T dateAsTextWave       // Assumed in YYYY-MM-DD format
    WAVE/T timeAsTextWave       // Assumed in HH:MM:DD format
    String outputWaveName

    Variable numPoints = numpnts(dateAsTextWave)
    Make/O/D/N=(numPoints) $outputWaveName
    WAVE wOut = $outputWaveName
    SetScale d, 0, 0, "dat", wOut
   
    Variable i
    for(i=0; i<numPoints; i+=1)
        String dateAsText = dateAsTextWave[i]
        String timeAsText = timeAsTextWave[i]
        Variable dt = ConvertTextToDateTime(dateAsText, timeAsText)
        wOut[i] = dt   
    endfor 
   
    return wOut
End

 

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More