473,440 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

DWORD date value

This is not strictly a C++ issue but if anyone will know the answer its you
guys!

I am trying to figure out a date format stored in the registry by a piece of
software (I am trying to write something to enable me to script a
configuration). The program stores a createdate for a set of registry keys
held in a DWORD value. I assumed it would be the number of seconds since
epoch (1/1/1970 00:00:00) - but its not. Here is a couple of examples:

19/12/2002 11:41:38 = 764632371
13/12/2002 11:36:58 = 764239005

Any one have any other ideas????

Thanks

Lee
Jul 19 '05 #1
6 22257
"Lee K" <no***@nothere.com> wrote...
This is not strictly a C++ issue but if anyone will know the answer its you guys!

I am trying to figure out a date format stored in the registry by a piece of software (I am trying to write something to enable me to script a
configuration). The program stores a createdate for a set of registry keys held in a DWORD value. I assumed it would be the number of seconds since
epoch (1/1/1970 00:00:00) - but its not. Here is a couple of examples:

19/12/2002 11:41:38 = 764632371
13/12/2002 11:36:58 = 764239005

Any one have any other ideas????


Looks like your DWORD is a (<date> << 16) + <time>. Perhaps even
the regular packed MSDOS date and time values. Remember those?

bits:

Date: YYYYYYYMMMMDDDDD
Time: HHHHHMMMMMMSSSSS, where S is half of real seconds.

So, to calculate the date you need to do

void breakDate(DWORD dvalue, int& year, int& month, int& day,
int& hour, int& minute, int& sec)
{
year = (dvalue >> 25) + 1980;
month = (dvalue >> 21) & 0xf;
day = (dvalue >> 16) & 0x1f;
hour = (dvalue >> 11) & 0x1f;
minute = (dvalue >> 5) & 0x3f;
sec = (dvalue & 0x1f) * 2;
}

It's possible to have invalid values. Month can be more than 12,
day can be more than the nubmer of days in the month, hours could
be > 23, minutes can be > 59, seconds could be > 59.

Victor
Jul 19 '05 #2
You are right - thank you very much.

What is the best way to actually create the DWORD value from the current
date?

Thanks,

Lee

"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vh************@corp.supernews.com...
"Lee K" <no***@nothere.com> wrote...
This is not strictly a C++ issue but if anyone will know the answer its you
guys!

I am trying to figure out a date format stored in the registry by a piece of
software (I am trying to write something to enable me to script a
configuration). The program stores a createdate for a set of registry

keys
held in a DWORD value. I assumed it would be the number of seconds

since epoch (1/1/1970 00:00:00) - but its not. Here is a couple of examples:

19/12/2002 11:41:38 = 764632371
13/12/2002 11:36:58 = 764239005

Any one have any other ideas????


Looks like your DWORD is a (<date> << 16) + <time>. Perhaps even
the regular packed MSDOS date and time values. Remember those?

bits:

Date: YYYYYYYMMMMDDDDD
Time: HHHHHMMMMMMSSSSS, where S is half of real seconds.

So, to calculate the date you need to do

void breakDate(DWORD dvalue, int& year, int& month, int& day,
int& hour, int& minute, int& sec)
{
year = (dvalue >> 25) + 1980;
month = (dvalue >> 21) & 0xf;
day = (dvalue >> 16) & 0x1f;
hour = (dvalue >> 11) & 0x1f;
minute = (dvalue >> 5) & 0x3f;
sec = (dvalue & 0x1f) * 2;
}

It's possible to have invalid values. Month can be more than 12,
day can be more than the nubmer of days in the month, hours could
be > 23, minutes can be > 59, seconds could be > 59.

Victor

Jul 19 '05 #3
"Lee K" <no***@nothere.com> wrote...
You are right - thank you very much.

What is the best way to actually create the DWORD value from the current
date?


Use << and | operators and just do the reverse of what
I did in the breakDate.

Victor
Jul 19 '05 #4
"Lee K" <no***@nothere.com> wrote...
Victor,

I tried that but am obviously making a school boy error as it does not work, any chance you could post an example???


If we want to make 'XXXKKKKKPPPP' out of three values x, k, and p,
then one approach could be

result = ((x & 7) << 9) | ((k & 31) << 4) | (p & 15);

Can you figure out why '7', '9', '31', '4', and '15'? Let it be
your homework.

Victor
Jul 19 '05 #5
Got the answer in the end thanks to Victor!

int yr = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int sec = 0;
CTime n = CTime::GetCurrentTime();
DWORD dValue = 0;

yr = n.GetYear();
month = n.GetMonth();
day = n.GetDay();
....

dValue = ((yr - 1980) << 25) | ((month & 0xF) << 21) | ((day & 0x1F) << 16)
| ((hour & 0x1F) << 11) | ((minute & 0x3F) << 5) | (sec / 2);

Thank you for your help.... This is why ng's are so great

Lee

"Lee K" <no***@nothere.com> wrote in message
news:3f***********************@mercury.nildram.net ...
This is not strictly a C++ issue but if anyone will know the answer its you guys!

I am trying to figure out a date format stored in the registry by a piece of software (I am trying to write something to enable me to script a
configuration). The program stores a createdate for a set of registry keys held in a DWORD value. I assumed it would be the number of seconds since
epoch (1/1/1970 00:00:00) - but its not. Here is a couple of examples:

19/12/2002 11:41:38 = 764632371
13/12/2002 11:36:58 = 764239005

Any one have any other ideas????

Thanks

Lee

Jul 19 '05 #6
"Lee K" <no***@nothere.com> wrote...
int yr = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int sec = 0;
CTime n = CTime::GetCurrentTime();
DWORD dValue = 0;

yr = n.GetYear();
month = n.GetMonth();
day = n.GetDay();
...

dValue = ((yr - 1980) << 25) | ((month & 0xF) << 21) | ((day & 0x1F) << 16) | ((hour & 0x1F) << 11) | ((minute & 0x3F) << 5) | (sec / 2);


Add some protection to this. Verify that the year you get is,
in fact >= 1980. Otherwise subtracting 1980 from it may lead
to unexpected or even undefined results.

Good luck with your project!

Victor
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: darrel | last post by:
I have the following right now to enter a date into SQL getting the data from some pull down menus: ------------------------------------------------- dim dateCCJApprovedDate as DateTime if...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
10
Cyberdyne
by: Cyberdyne | last post by:
Here is the problem, I have a form with a field named Occurence with a Short Date Value, once entered it subsequently appears in 3 fields SOL1 which adds one year, SOL2 which adds 2 years and...
6
by: Aussie Rules | last post by:
Hi, I have a datepicker that show a calender. The user picks a date and the time component is always 00:00. I then have a drop down that provides a list of times, (10:00, 11:00 etc), and I...
2
by: MackTheKnife | last post by:
Hi, I'm trying to write a java.sql.Date to a database and the minutes/ seconds etc. are not being written. I've seen and tested many examples found via searches and still have come up with...
0
by: salo | last post by:
Hi ........Im working with c# and asp.net and i have two calendar control in my form and i want the cliked date value to be get displayed in the textbox. i gave the code as ...
3
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. ...
8
by: Rob Wilkerson | last post by:
Surprisingly (at least to me), there doesn't seem to be a built-in function to validate a date value (like, say, is_date()). Given that, is there a best practice for determining whether a value is...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.