DWORD date value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee K

    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


  • Victor Bazarov

    #2
    Re: DWORD date value

    "Lee K" <notme@nothere. com> wrote...[color=blue]
    > This is not strictly a C++ issue but if anyone will know the answer its[/color]
    you[color=blue]
    > guys!
    >
    > I am trying to figure out a date format stored in the registry by a piece[/color]
    of[color=blue]
    > software (I am trying to write something to enable me to script a
    > configuration). The program stores a createdate for a set of registry[/color]
    keys[color=blue]
    > 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????[/color]

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

    bits:

    Date: YYYYYYYMMMMDDDD D
    Time: HHHHHMMMMMMSSSS S, 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


    Comment

    • Lee K

      #3
      Re: DWORD date value

      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.Abazarov@att Abi.com> wrote in message
      news:vhdtf1o344 bd76@corp.super news.com...[color=blue]
      > "Lee K" <notme@nothere. com> wrote...[color=green]
      > > This is not strictly a C++ issue but if anyone will know the answer its[/color]
      > you[color=green]
      > > guys!
      > >
      > > I am trying to figure out a date format stored in the registry by a[/color][/color]
      piece[color=blue]
      > of[color=green]
      > > software (I am trying to write something to enable me to script a
      > > configuration). The program stores a createdate for a set of registry[/color]
      > keys[color=green]
      > > held in a DWORD value. I assumed it would be the number of seconds[/color][/color]
      since[color=blue][color=green]
      > > 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????[/color]
      >
      > Looks like your DWORD is a (<date> << 16) + <time>. Perhaps even
      > the regular packed MSDOS date and time values. Remember those?
      >
      > bits:
      >
      > Date: YYYYYYYMMMMDDDD D
      > Time: HHHHHMMMMMMSSSS S, 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
      >
      >[/color]


      Comment

      • Victor Bazarov

        #4
        Re: DWORD date value

        "Lee K" <notme@nothere. com> wrote...[color=blue]
        > You are right - thank you very much.
        >
        > What is the best way to actually create the DWORD value from the current
        > date?[/color]

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

        Victor


        Comment

        • Victor Bazarov

          #5
          Re: DWORD date value

          "Lee K" <notme@nothere. com> wrote...[color=blue]
          > Victor,
          >
          > I tried that but am obviously making a school boy error as it does not[/color]
          work,[color=blue]
          > any chance you could post an example???[/color]

          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


          Comment

          • Lee K

            #6
            Re: DWORD date value

            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::GetCurre ntTime();
            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" <notme@nothere. com> wrote in message
            news:3f16ed99$0 $45170$65c69314 @mercury.nildra m.net...[color=blue]
            > This is not strictly a C++ issue but if anyone will know the answer its[/color]
            you[color=blue]
            > guys!
            >
            > I am trying to figure out a date format stored in the registry by a piece[/color]
            of[color=blue]
            > software (I am trying to write something to enable me to script a
            > configuration). The program stores a createdate for a set of registry[/color]
            keys[color=blue]
            > 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
            >
            >[/color]


            Comment

            • Victor Bazarov

              #7
              Re: DWORD date value

              "Lee K" <notme@nothere. com> wrote...[color=blue]
              > int yr = 0;
              > int month = 0;
              > int day = 0;
              > int hour = 0;
              > int minute = 0;
              > int sec = 0;
              > CTime n = CTime::GetCurre ntTime();
              > DWORD dValue = 0;
              >
              > yr = n.GetYear();
              > month = n.GetMonth();
              > day = n.GetDay();
              > ...
              >
              > dValue = ((yr - 1980) << 25) | ((month & 0xF) << 21) | ((day & 0x1F) <<[/color]
              16)[color=blue]
              > | ((hour & 0x1F) << 11) | ((minute & 0x3F) << 5) | (sec / 2);[/color]

              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


              Comment

              Working...