Board index » delphi » converting packed 16Bit DOS time/date

converting packed 16Bit DOS time/date

Hi,

can anyone tell me, how i convert the 16bit packed DOS time/date ?

The format is:

DOSTIME

0-4 Second divided by 2
5-10 Minute (0-59)
11-15 Hour (0-23 on a 24-hour clock)

DOSDATE

0-4 Day of month (1-31)
5-8 Month (1-12)
9-15 Year offset from 1980

I want to convert from and to this format.

thanks,
Karsten (kle...@aol.com)

 

Re:converting packed 16Bit DOS time/date


Quote
In article <4e2f6e$...@newsbf02.news.aol.com> kle...@aol.com (KlemmK) writes:
>Hi,
>can anyone tell me, how i convert the 16bit packed DOS time/date ?
>The format is:
>DOSTIME
>0-4 Second divided by 2
>5-10 Minute (0-59)
>11-15 Hour (0-23 on a 24-hour clock)
>DOSDATE
>0-4 Day of month (1-31)
>5-8 Month (1-12)
>9-15 Year offset from 1980
>I want to convert from and to this format.

I'm 99% certain that this is the packed format used by PackTime and
UnpackTime in the DOS unit.  The only difference is that These procedures
use a longint rather than two words.  [Shuffling through old books . . .]
Okay, it appears that the packed time will come first, then the packed date.
So, the time is in the low word of the longint, and the date is in the high
word.

Quote
>thanks,
>Karsten (kle...@aol.com)

--
Scott F. Earnest             |0100100001000001010010010100110000100000|
sc...@whiplash.res.cmu.edu   |0100010101010010010010010101001100100001|
Head Pope, Non-Extant Temple of Afrodite, Goddess of Funky 70's Hairdos -><-
      YOU'VE BEEN LIED TO:  Possession is only one tenth of the law.
                The other nine tenths is really STUPIDITY!

Re:converting packed 16Bit DOS time/date


Quote
>can anyone tell me, how i convert the 16bit packed DOS time/date ?
>The format is:
>DOSTIME
>0-4 Second divided by 2
>5-10 Minute (0-59)
>11-15 Hour (0-23 on a 24-hour clock)
>DOSDATE
>0-4 Day of month (1-31)
>5-8 Month (1-12)
>9-15 Year offset from 1980

     To do the conversion, you need to understand how the "mod" and "div"
operators work (or, if you like using non-standard, i.e. Borland, operators,
you need to understand shifts).  Next, notice that encoding time and date into
bits is equivalent to expressing it as a product, with the multipliers being
powers of 2.  Thus, for example,
        DosDate := day + 32 * (month + 4 * (year - 1980);
The rest is left as an (almost trivial) exercise for the reader.

Bob Schor
Pascal Enthusiast

Quote
>thanks,
>Karsten (kle...@aol.com)

Re:converting packed 16Bit DOS time/date


                                                 25 Jan 96

Hi folks,

  kle...@aol.com (KlemmK)  wrote on 23.01.96 at /COMP/LANG/PASCAL/BORLAND
under the topic of "converting packed 16Bit DOS time/date" (MsgID: 4e2f6e$...@newsbf02.news.aol.com)

 k> can anyone tell me, how i convert the 16bit packed DOS time/date ?

 If you are using Turbo or Borland Pascal use the procedures

 PackTime (VAR dt : DateTime; VAR time : Longint);

 UnpackTime (time : Longint; VAR dt : DateTime);

 The record DateTime and both procedures are defined in the unit DOS.

 cu

 Hendrik

Re:converting packed 16Bit DOS time/date


In article 0195C...@vms.cis.pitt.edu, bsc...@vms.cis.pitt.edu (Bob Schor) writes:

Quote
> >can anyone tell me, how i convert the 16bit packed DOS time/date ?

> >The format is:

> >DOSTIME

> >0-4 Second divided by 2
> >5-10 Minute (0-59)
> >11-15 Hour (0-23 on a 24-hour clock)

> >DOSDATE

> >0-4 Day of month (1-31)
> >5-8 Month (1-12)
> >9-15 Year offset from 1980

>      To do the conversion, you need to understand how the "mod" and "div"
> operators work (or, if you like using non-standard, i.e. Borland, operators,
> you need to understand shifts).  Next, notice that encoding time and date into
> bits is equivalent to expressing it as a product, with the multipliers being
> powers of 2.  Thus, for example,
>    DosDate := day + 32 * (month + 4 * (year - 1980);
> The rest is left as an (almost trivial) exercise for the reader.

> Bob Schor
> Pascal Enthusiast

> >thanks,
> >Karsten (kle...@aol.com)

Hi,

IMHO, a simple way to do this would be using the procedures PackTime and
UnPackTime which are provided in the DOS unit.
I don't remember the syntax, but all is explained in the online help.

Hope this will help.

Bye.

Christophe.

Re:converting packed 16Bit DOS time/date


     It has been drawn to my attention that I made a stupid mistake in an
earlier followup to this question (how embarassing!).  The formula should say
  ... 16 * (year - 1980)
instead of
  ...  4 * (year - 1980).

     It is a shift of 4, which corresponds to a multiplication of 2**4 = 16.  
Sigh.

Bob Schor
Pascal Enthusiast (but sometimes clumsy with exponents)

Re:converting packed 16Bit DOS time/date


On 29 Jan 96 (06:01), kle...@aol.com wrote:

Quote
> Hi,

> can anyone tell me, how i convert the 16bit packed DOS time/date ?

PackTime ands UnpackTime..... look it up in the online help.
I answered your question some time ago in de.comp.lang.pascal, why did you  
ask again ? You recieved some really useful answers...

Stephan

-------------------------------------------------------------------------
 Stephan A. Maciej   step...@maciej.muc.de   http://www.muc.de/~stephanm
       <<< Bug is a registered trademark of Microsoft Corp. >>>
-------------------------------------------------------------------------

Other Threads