Microsoft KB Archive/39916

{|
 * width="100%"|

Example Using _dos_findfirst to Get the Time and Date

 * }

Q39916

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 MS-DOS | OS/2 | WINDOWS kbprg kbcode -- The information in this article applies to: - The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax - Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, version 1.0 -- SUMMARY ======= The code below illustrates how to extract the time and the date out of the C run-time function _dos_findfirst. The program prints out the time and the date of the creation of the file &quot;test&quot;. This information also applies to QuickC. MORE INFORMATION ================ The time at which the file was last written to is returned as a binary value in a word formatted as follows: Bits Meaning --- 0-4 Number of seconds DIVIDED BY TWO (to find actual number of seconds, multiply by two) 5-10 Minutes 11-15 Hours, based on a 24-hour clock The date at which the file was last written to is returned as a binary value in a word formatted as follows: Bits Meaning  --- 0-4 Day of the month 5-8 Month (1 = January and so on) 9-15 This number plus 1980 give current year Sample Code --- /* Compile options needed: none */ #include #include #include struct low_unit { unsigned biseconds: 5; /* in units of TWO seconds */ unsigned minutes: 6; unsigned hours: 5; } *ptime; struct hi_unit { unsigned day: 5; unsigned month: 4; unsigned year: 7; } *pdate; struct find_t c_file; void main(void) { _dos_findfirst (&quot;test&quot;, _A_NORMAL, &c_file); system(&quot;cls&quot;); ptime = (struct low_unit *) &c_file.wr_time; pdate = (struct hi_unit *) &c_file.wr_date; printf (&quot;Created at %u:%u:%u&quot;,\ ptime->hours, ptime->minutes, ptime->biseconds * 2); /* NOTE: seconds are divided by two when stored, so we have to multiply by two to get the proper value.... */ printf (&quot; on %u-%u-%u.&quot;,\ pdate->month, pdate->day, pdate->year + 80); } The program might produce the following output (depending on when the file &quot;test&quot; was created): Created at 10:32:28 on 12-19-89 Note that the seconds field of the time will always be even. For more information on function _dos_findfirst, see the Microsoft C Run-Time Library Reference.&quot; Additional reference words: kbinf 5.00 5.10 6.00 6.00a 6.00ax 7.00 1.00 KBCategory: kbprg kbcode KBSubcategory: CRTIss

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT