A structure representing a single date item within a date collection
DATE_ITEM is a structure that represents a single date item within a date collection or date log. It contains date information in various formats (FILETIME, SYSTEMTIME, large integer, date number) to support flexible date representation and manipulation across the mdts_date library.
The structure maintains date information and provides access through multiple representations, allowing callers to retrieve and work with dates in their preferred format. This structure is used extensively when working with date collections, date logs, and date-based operations.
The DATE_ITEM structure is defined in datelog.h as follows:
typedef struct _DATE_ITEM {
FILETIME FileTime; /* Date represented as FILETIME */
SYSTEMTIME SystemTime; /* Date represented as SYSTEMTIME */
LARGE_INTEGER LargeInteger; /* Date represented as large integer */
double DateNumber; /* Date represented as date number (e.g., OLE Date) */
} DATE_ITEM, *PDATE_ITEM;
The date and time in FILETIME format (Windows 64-bit file time). FILETIME represents time as the number of 100-nanosecond intervals since January 1, 1601.
The date and time in SYSTEMTIME format, containing year, month, day, hour, minute, second, and millisecond fields.
The date represented as a 64-bit large integer, useful for arithmetic operations and comparisons at a low level.
The date represented as a double-precision floating-point number (OLE Date format), where the integer part represents days since December 30, 1899, and the fractional part represents the time of day.
InitializeDateItem() function to ensure proper initialization and validation.GetDateItemFiletime(), GetDateItemDate(), etc., rather than accessing the structure members directly.To create a DATE_ITEM, use the InitializeDateItem() function:
DATE_ITEM dateItem = {0};
HRESULT hr = InitializeDateItem(
&dateItem, /* Output parameter */
2024, 12, 25, /* Year, Month, Day */
12, 30, 45, 0 /* Hour, Minute, Second, Milliseconds */
);
if (FAILED(hr)) {
/* Handle error */
}
Use accessor functions to retrieve date information in your preferred format:
FILETIME ft = GetDateItemFiletime(&dateItem);
SYSTEMTIME st = GetDateItemSystemTime(&dateItem);
LARGE_INTEGER li = GetDateItemLargeInteger(&dateItem);
double dateNum = GetDateItemNumber(&dateItem);
Compare two DATE_ITEM structures using the comparison function:
DATE_ITEM item1 = {0}, item2 = {0};
/* Initialize item1 and item2 ... */
int result = CompareDateItem(&item1, &item2);
if (result < 0) {
/* item1 is before item2 */
} else if (result > 0) {
/* item1 is after item2 */
} else {
/* item1 equals item2 */
}
DATE_ITEM structures are used when working with date collections and date logs:
DATE_COLLECTION_HANDLE hCollection = /* ... */;
DATE_ITEM dateItem = {0};
/* Find a date item in the collection */
HRESULT hr = FindDateItemHandle(
hCollection,
NULL, /* Start from beginning */
&dateItem, /* Output: found date item */
NULL /* No gap information needed */
);
#include "datelog.h"
#include
int main(void)
{
HRESULT hr = S_OK;
DATE_ITEM dateItem = {0};
FILETIME ft = {0};
SYSTEMTIME st = {0};
/* Initialize a date item for December 25, 2024, 12:30:45 */
hr = InitializeDateItem(
&dateItem,
2024, 12, 25,
12, 30, 45, 0
);
if (FAILED(hr)) {
printf("Failed to initialize date item.\n");
return 1;
}
/* Retrieve the date in FILETIME format */
ft = GetDateItemFiletime(&dateItem);
printf("FILETIME: %lld\n", *(unsigned long long*)&ft);
/* Retrieve the date in SYSTEMTIME format */
st = GetDateItemSystemTime(&dateItem);
printf("Date: %04d-%02d-%02d %02d:%02d:%02d\n",
st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond);
/* Retrieve the date as a date number (OLE format) */
double dateNum = GetDateItemNumber(&dateItem);
printf("Date Number (OLE): %.2f\n", dateNum);
/* Compare with another date */
DATE_ITEM anotherItem = {0};
hr = InitializeDateItem(
&anotherItem,
2024, 12, 26,
12, 0, 0, 0
);
if (SUCCEEDED(hr)) {
int cmp = CompareDateItem(&dateItem, &anotherItem);
printf("Comparison result: %d (negative means first is earlier)\n", cmp);
}
/* Cleanup - free the date item if necessary */
hr = FreeDateItem(&dateItem);
return 0;
}