String to dt

Hello,

Is there any function to convert directly a string containing a time stamp from mappAlarmXHistoryUI list to DT format?

I have tried STRING_TO_DT but is does work.

Also using a DT structure and the function DTStructure_TO_DT does not convert properly, maybe because I cannot get the week day from the alarm list.

Thank you!

Hi @Pedro_Antonio

I don’t think if there is a build-in function for that but you can easily parse the string to get all part of the date, but that in a DTStructure then convert the DTStructure to DT datatype, DATE_AND_TIME datatype store seconds so you don’t have to parse the milliseconds.
Here is an example in ST using AsBrStr lib, I don’t remember if we can change the format but for information I use the format 2026-06-15 09:47:18:100:

// Parse timestamp string to DT format
// Expected format: 'YYYY-MM-DD HH:MM:SS:mmm' (e.g., '2026-06-15 09:47:18:100')
IF AlarmeHistoryUIConnect.AlarmList.Timestamp[0] <> '' THEN
	// Extract year (positions 0-3 in 0-based indexing)
	brsmemset(ADR(strYear), 0, SIZEOF(strYear));
	brsmemcpy(ADR(strYear), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]), 4);
	year := STRING_TO_UINT(strYear);
	
	// Extract month (positions 5-6)
	brsmemset(ADR(strMonth), 0, SIZEOF(strMonth));
	brsmemcpy(ADR(strMonth), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]) + 5, 2);
	month := STRING_TO_USINT(strMonth);
	
	// Extract day (positions 8-9)
	brsmemset(ADR(strDay), 0, SIZEOF(strDay));
	brsmemcpy(ADR(strDay), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]) + 8, 2);
	day := STRING_TO_USINT(strDay);
	
	// Extract hour (positions 11-12)
	brsmemset(ADR(strHour), 0, SIZEOF(strHour));
	brsmemcpy(ADR(strHour), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]) + 11, 2);
	hour := STRING_TO_USINT(strHour);
	
	// Extract minute (positions 14-15)
	brsmemset(ADR(strMinute), 0, SIZEOF(strMinute));
	brsmemcpy(ADR(strMinute), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]) + 14, 2);
	minute := STRING_TO_USINT(strMinute);
	
	// Extract second (positions 17-18)
	brsmemset(ADR(strSecond), 0, SIZEOF(strSecond));
	brsmemcpy(ADR(strSecond), ADR(AlarmeHistoryUIConnect.AlarmList.Timestamp[0]) + 17, 2);
	second := STRING_TO_USINT(strSecond);
	
	// Build DTStructure
	dtStructure.year := year;
	dtStructure.month := month;
	dtStructure.day := day;
	dtStructure.hour := hour;
	dtStructure.minute := minute;
	dtStructure.second := second;
	dtStructure.millisec := 0;
	dtStructure.microsec := 0;
	dtStructure.wday := 0;
	
	// Convert DTStructure to DT
	parsedDateTime := DTStructure_TO_DT(ADR(dtStructure));
	
END_IF;

For the variables:

(*TIMESTAMP PARSING VARIABLES*)
VAR
	strYear : STRING[4]; (*Temporary string for year extraction*)
	strMonth : STRING[2]; (*Temporary string for month extraction*)
	strDay : STRING[2]; (*Temporary string for day extraction*)
	strHour : STRING[2]; (*Temporary string for hour extraction*)
	strMinute : STRING[2]; (*Temporary string for minute extraction*)
	strSecond : STRING[2]; (*Temporary string for second extraction*)
	year : UINT; (*Parsed year value*)
	month : USINT; (*Parsed month value*)
	day : USINT; (*Parsed day value*)
	hour : USINT; (*Parsed hour value*)
	minute : USINT; (*Parsed minute value*)
	second : USINT; (*Parsed second value*)
	dtStructure : DTStructure; (*Structure for date/time conversion*)
	parsedDateTime : DT; (*Final parsed date and time*)
END_VAR

I think you can create a user function to handle this on your side.

Hope it help!

Regards,
Florent

Thank you very much!

It works!