Support Board
Date/Time: Sun, 24 Nov 2024 15:47:08 +0000
[Programming Help] - Getting the Seconds between 2 SCDateTime objects, which may or may not be > 24 hrs
View Count: 283
[2024-05-21 15:38:46] |
ycomp - Posts: 318 |
How can I get the # of seconds difference between 2 SCDateTime objects, even if it is more than 24 hours between them? currently I'm using .GetAsDouble() to find the difference in double.. then I can make a SCDateTime from that double, but I can't figure out how convert that to seconds? is there a way I can just convert the double directly to seconds? for ease of reference: Working with the SCDateTime Variables and Values Date Time Of Last Edit: 2024-05-21 15:40:37
|
[2024-05-21 16:17:01] |
User431178 - Posts: 541 |
is there a way I can just convert the double directly to seconds? Multiply double value by seconds per day, 86400, that is all. Date Time Of Last Edit: 2024-05-21 16:17:15
|
[2024-05-22 08:02:10] |
ycomp - Posts: 318 |
great, much appreciated
|
[2024-05-22 10:02:53] |
ycomp - Posts: 318 |
/*** Total Seconds (i.e. that can be > 24 hours) ***/
inline constexpr double SECONDS_IN_DAY = 24 * 60 * 60; /** * @param seconds the total seconds * @return the SCDateTime value */ inline SCDateTime fromSeconds(int64_t seconds) { return SCDateTime{ seconds / SECONDS_IN_DAY }; } /** * @param dt the SCDateTime * @return the SCDateTime value as total seconds */ inline int64_t seconds(const SCDateTime& dt) { return static_cast<int64_t>( dt.GetAsDouble() * SECONDS_IN_DAY); } /** * @param dt1 the first SCDateTime * @param dt2 the second SCDateTime * @return the number of seconds between dt1 and dt2 * - positive if dt1 is later than dt2, negative if dt1 is earlier than dt2 */ inline int seconds(const SCDateTime& dt1, const SCDateTime& dt2) { return static_cast<int>( seconds(dt1) - seconds(dt2) ); } |
To post a message in this thread, you need to log in with your Sierra Chart account: