473,385 Members | 1,615 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,385 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 22250
"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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.