Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 07:46:53 +0000



best way to convert SCDateTime to db and back

View Count: 984

[2020-08-29 08:21:58]
User658985 - Posts: 30
I'm reworking all my studies to support the new SCDateTime format. I tried a couple of things and it didn't quite work, thought i'd just ask you guys. So whats the best way to save this as a string to a db, then convert it back to SCDateTime? From what i understand, its an int now, so i tried something like this but didnt work:


int dateInt = sc.CurrentSystemDateTime.GetDate();
  SCString dateStr = SCString().Format("%d", dateInt);
  SCDateTime dt;
  dt.SetDate(dateInt);


I could simply just continue to save it as a double. Is there a preferred way that allows for better future compatibility?
[2020-08-31 16:46:13]
Sierra Chart Engineering - Posts: 104368
Refer to this function:
Working with the SCDateTime Variables and Values: GetAsDouble()
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2021-10-11 17:03:01]
User99735 - Posts: 234
Hi,
Roundtripping of SCDateTimeMS to double and back is not working.
SCDateTimeMS startDateTime = SCDateTimeMS(2021, 10, 7, 1, 1, 1);
double datetime = startDateTime.GetAsDouble();

SCDateTimeMS endDateTime = SCDateTimeMS(datetime);
sc.AddMessageToLog(SCString().Format("datetime %s", sc.DateTimeToString(endDateTime, FLAG_DT_COMPLETE_DATETIME_MS)), false);

is printing gibberish.

Vivek
[2021-10-12 03:29:03]
Sierra_Chart Engineering - Posts: 14092
There is a mistake in your code.

This does not return a string pointer:
sc.DateTimeToString(endDateTime, FLAG_DT_COMPLETE_DATETIME_MS)

Refer to:
ACSIL Programming Concepts: Working with SCString, Text Strings and Setting ACSIL Structure Member Name Strings
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account