News:

  • August 04, 2026, 09:00:05 AM

Login with username, password and session length

Author Topic: Date Structure Explanation  (Read 8113 times)

Bolt

  • Hero Member
  • *****
  • Posts: 598
Date Structure Explanation
« on: June 08, 2023, 05:07:19 PM »
How does a .Date structure work? How could it be deciphered externally? I know that today is 132580872, and The help file says "a signed 32-bit value that contains the .Year, .Month,and .Day field values packed into a single location (YYYYMMDD)", but I'm having a hard time figuring out how to interpret it. I'm trying to use it in a report generated via REST API, and wondering how to best decode it. I know I could do a STRPRINT to format the date, but trying to keep it non-string for the moment.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Date Structure Explanation
« Reply #1 on: June 08, 2023, 05:48:07 PM »
How does a .Date structure work? How could it be deciphered externally? I know that today is 132580872, and The help file says "a signed 32-bit value that contains the .Year, .Month,and .Day field values packed into a single location (YYYYMMDD)", but I'm having a hard time figuring out how to interpret it. I'm trying to use it in a report generated via REST API, and wondering how to best decode it. I know I could do a STRPRINT to format the date, but trying to keep it non-string for the moment.

View it in hex. Low byte is day. Next byte up is month. Upper word is year.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Date Structure Explanation
« Reply #2 on: June 08, 2023, 06:08:14 PM »
Well that was easy.

Now if I were to create a block containing dates, MyBlock0-99.Date, with MyBlock0.Date being today, MyBlock1.Date being yesterday, etc, how could I accomplish that? I know I could shift the whole block down 1 notch every new day and write $Now.Date to it, but looking to do it retroactively with a daily summary task, looping through records and tabulating them for each day when requested.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Date Structure Explanation
« Reply #3 on: June 08, 2023, 06:15:00 PM »
Well that was easy.

Now if I were to create a block containing dates, MyBlock0-99.Date, with MyBlock0.Date being today, MyBlock1.Date being yesterday, etc, how could I accomplish that? I know I could shift the whole block down 1 notch every new day and write $Now.Date to it, but looking to do it retroactively with a daily summary task, looping through records and tabulating them for each day when requested.

FIFO works great for that or you can roll your own with a ring ring buffer.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3839
    • Host Engineering
Re: Date Structure Explanation
« Reply #4 on: June 09, 2023, 09:48:40 AM »
It's a union of the 3 Date fields as a single DWORD.  The Date/Time structure memory layout is as follows.  So the DWORD offset 0 in memory of a Date/Time structure contains the 3 parts of the date field (.Year in WORD1, .Month in BYTE1, .Day in BYTE0), OR look at it as a single DWORD as .Date

Code: [Select]
"Date/Time Struct" Structure Memory Layout (2 total DWORDs in length, DWORD Offset 0..1)
+------++----------------------------------------------------------------------------------------------------------------------------------++
|      || Most Significant                                                                                               Least Significant ||
|      ++----------------------------------------------------------------------------------------------------------------------------------++
|      ||                                                              DWORD                                                               ||
|      ++----------------------------------------------------------------++----------------------------------------------------------------++
|      ||                             WORD 1                             ||                             WORD 0                             ||
|      ++-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|      ||             BYTE 3            ||             BYTE 2            ||             BYTE 1            ||             BYTE 0            ||
|DWORD ++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++
|Offset||b31|b30|b29|b28|b27|b26|b25|b24||b23|b22|b21|b20|b19|b18|b17|b16||b15|b14|b13|b12|b11|b10| b9| b8|| b7| b6| b5| b4| b3| b2| b1| b0||
+------++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++
Note: Every Bit Field layout only shows the Field # (no name).  See the list of Bit Field Names listed by Field # at the end.

+------++----------------------------------------------------------------++-------------------------------++-------------------------------++
|    0 ||   2                         .Year                        UWORD ||   3         .Month      UBYTE ||   4          .Day       UBYTE ||
|      ||----------------------------------------------------------------++-------------------------------++-------------------------------++
|      ||   1                                                          .Date                                                        SDWORD ||
+------++-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|    1 ||   6       .DayOfWeek    UBYTE ||   7         .Hour       UBYTE ||   8        .Minute      UBYTE ||   9        .Second      UBYTE ||
|      ||-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|      ||   5                                                          .Time                                                        SDWORD ||
+------++----------------------------------------------------------------------------------------------------------------------------------++