Support Board
Date/Time: Mon, 15 Sep 2025 13:35:07 +0000
[User Discussion] - [Programming help] transferring an ISO date to SCDateTime
View Count: 62
[2025-09-14 07:11:36] |
swish - Posts: 3 |
I am loading in an ISO date, example: 2025-08-29T19:59:54.957947625Z I am wondering the best method to transfer this into the most accurate SCDateTime I can with both the date and time being correct. Here is what I have now, however, it appears to be setting my value to JUST the date SCDateTime sc_date_time = sc.DateStringToSCDateTime((const char*)ISO_TIME); I also tried sc.TimeStringToSCDateTime() but that does not seem to give me the result I want either |
[2025-09-14 15:56:14] |
Tony - Posts: 625 |
I would read the whole ISO string to a SCString variable, and just get sub-strings, i.e. SCString ISO_String {2025-08-29T19:59:54.957947625Z};
int ISO_Minute { atoi(ISO_String.GetSubString(2,14).GetChars()) }; |
[2025-09-14 17:16:53] |
User431178 - Posts: 779 |
Split the ISO datetime string into date and time, then use the functions you mentioned. ACSIL Interface Members - Functions: sc.DateStringToSCDateTime() ACSIL Interface Members - Functions: sc.TimeStringToSCDateTime() When you have done that you will have two objects, date and time, use the time object to set the time of the date object. Another option would be to use the use the standard c++ features to read in and convert to SCDateTime. https://cplusplus.com/reference/iomanip/get_time/ https://cplusplus.com/reference/ctime/tm/ |
[2025-09-14 20:34:39] |
swish - Posts: 3 |
Thanks to both of you. I ended up doing this, it may not be the most effecient way but it worked for my purposes: Working with the SCDateTime Variables and Values: SetDateTimeYMDHMS() SCDateTime sc_datetime;
SCString timeStr((const char*)time_str); std::string t((const char*)timeStr); for (auto& c : t) if (c == 'T') c = ' '; if (!t.empty() && t.back() == 'Z') t.pop_back(); size_t dotPos = t.find('.'); if (dotPos != std::string::npos) t = t.substr(0, dotPos); int year, month, day, hour, minute, second; sscanf(t.c_str(), "%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second); sc_datetime.SetDateTimeYMDHMS(year, month, day, hour, minute, second); Date Time Of Last Edit: 2025-09-14 20:35:46
|
To post a message in this thread, you need to log in with your Sierra Chart account: