Re: How do I put the date time into a DWORD? by Vincent
Vincent
Mon Feb 06 20:32:09 CST 2006
which is a lot like the following which will 'encode' a time to the nearest
2 seconds (and not be suitable for computation):
SYSTEMTIME st; /* fill in this one */
FILETIME ft;
WORD wFatDate, wFatTime;
SystemTimeToFileTime(&st, &ft)
FileTimeToDosDateTime(&ft, &wFatDate, &wFatTime)
DWORD dwTime = MAKELONG(wFatTime, wFatDate)
On Mon, 6 Feb 2006 17:22:25 -0800, "Joe" <joe@nospam.org> wrote:
>You probably want to do something like this:
>
>DWORD date_time_value = 0;
>date_time_value |= ((wHour & 0x1F) << 0); // 0
>date_time_value |= ((wMonth & 0x0F) << 5); // 0+5
>date_time_value |= ((wMinute & 0x3F) << 9); // 0+5+4
>date_time_value |= ((wSecond& 0x3F) << 15); // 0+5+4+6
>date_time_value |= ((wYear & 0x3FF) << 21); // 0+5+4+6+6
>
>wMonth = ((date_time_value>> 0)& 0x1F);
>wHour = ((date_time_value>> 5)& 0x0F);
>wMinute = ((date_time_value>> 9)& 0x3F);
>wSecond = ((date_time_value>> 15)& 0x3F);
>wYear = ((date_time_value>> 21)& 0x3FF);
>
>This is because:
>
>wHour ranges from 0 to 23, 24 unique values, requires 5 bits ( 32 unique
>values) to store
>wMonth ranges from 0 to 11, 12 unique values, requires 4 bits (16 unique
>values) to store.
>wMinute ranges from 0 to 59, 60 unique values, requires 6 bits (64 unique
>values) to store.
>wSecond ranges from 0 to 59, 60 unique values, requires 6 bits (64 unique
>values) to store
>
>So far, this encoding requires 5 + 4 + 6 + 6 = 21 bits. DWORD has 32 bits,
>so 32 - 21 = 11 bits (2048 unique values) remain.
>
>So, now you have to figure out what your range of wYear will be.
>
>If wYear ranges from 0 to 2047, then 11 bits will work.
>If wYear ranges from 1900 to 3947, then 11 bits will work.
>If wYear ranges from 0 to 4000, then 11 bits will NOT work.
>
>
><joseph_mueller@yahoo.com> wrote in message
>news:1139265370.483911.89000@g43g2000cwa.googlegroups.com...
>> What I am trying to do is something like this.
>>
>> DWORD dwTime;
>>
>> dwTime = whatever I can piece together with st.wDay, st.wMonth,
>> st.wYear, st.wHour, st.wMinute, and st.wSecond
>>
>
--
- Vince