I have the system time but I do not know how to put the various pieces
(st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond) into a
DWORD.

SYSTEMTIME st;
GetSystemTime(&st);

Thank you in advance.

Re: How do I put the date time into a DWORD? by Tom

Tom
Mon Feb 06 16:31:05 CST 2006

I'm not sure exactly what you're trying to do, but if you are looking for
total "seconds" you could always just multiply the numbers out. Or, you
could assign it to a CTime and use CTimeSpan. Or, you could use
COleDateTime:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_coledatetime.asp

Tom

<joseph_mueller@yahoo.com> wrote in message
news:1139264489.355140.30190@g43g2000cwa.googlegroups.com...
>I have the system time but I do not know how to put the various pieces
> (st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond) into a
> DWORD.
>
> SYSTEMTIME st;
> GetSystemTime(&st);
>
> Thank you in advance.
>



Re: How do I put the date time into a DWORD? by joseph_mueller

joseph_mueller
Mon Feb 06 16:36:10 CST 2006

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


Re: How do I put the date time into a DWORD? by Igor

Igor
Mon Feb 06 16:46:35 CST 2006

joseph_mueller@yahoo.com wrote:
> 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

How do you plan to use it after you pack it?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: How do I put the date time into a DWORD? by Tom

Tom
Mon Feb 06 17:33:36 CST 2006

If you don't care so long as it is a "number" you might just want to do
number of seconds since epoch (1970) so you can convert back and forth
easily. I don't think there are any automatic ways to do that unless you
just use a time_t.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_mktime.asp

Tom

<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
>



Re: How do I put the date time into a DWORD? by Joe

Joe
Mon Feb 06 19:22:25 CST 2006

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
>



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