Jump to content

DosGetDateTime (OS/2 1.x): Difference between revisions

From EDM2
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[image:legacy.png]]
{{Legacy
This is the legacy function. It is recommended to use:  [[OS2 API:CPI:DosGetDateTime|DosGetDateTime]]
|RepFunc=[[DosGetDateTime]]
 
|Remarks=The function described here was part of the OS2 1.x API. It had been updated for modern OS/2 development, it is available at [[DosGetDateTime]].
==Description==
}}
This call gets the current date and time maintained by the operating system.  
This call gets the current date and time maintained by the operating system.


==Syntax==
==Syntax==
<PRE>
  DosGetDateTime (DateTime)
  DosGetDateTime


    (DateTime)
</PRE>
==Parameters==
==Parameters==
; DateTime (PDATETIME) - output : Address of the date and time structure:
;DateTime (P[[DATETIME]]) - output : Address of the date and time structure.
 
* hours (UCHAR)
        Current hour.
* minutes (UCHAR)
        Current minute.
* seconds (UCHAR)
        Current second.
* hundredths (UCHAR)
        Current hundredth of a second.
* day (UCHAR)
        Current day.
* month (UCHAR)
        Current month.
* year (USHORT)
        Current year.
* timezone (SHORT)
        Minutes west of UTC (Universal Time Coordinate).
* weekday (UCHAR)
        Current day of the week. Sunday is 0.


==Return Code==
==Return Code==
rc (USHORT) - return
;rc (USHORT) - return:Return code description is:
 
*0 NO_ERROR
Return code description is:
 
* 0   NO_ERROR


==Remarks==
==Remarks==
The dayofweek value is based on Sunday equal to zero. The value of timezone is the difference in minutes between the current time zone and UTC. This number is positive if it is earlier than UTC and negative if it is later than UTC. For Eastern Standard Time, this value is 300 (5 hours earlier than UTC).
The dayofweek value is based on Sunday equal to zero. The value of timezone is the difference in minutes between the current time zone and UTC. This number is positive if it is earlier than UTC and negative if it is later than UTC. For Eastern Standard Time, this value is 300 (5 hours earlier than UTC).


If the application is executing in the OS/2 environment, it is more efficient to obtain these variables by calling DosGetInfoSeg instead of this function. However, applications written to the family API cannot depend on the availability of DosGetInfoSeg.  
If the application is executing in the OS/2 environment, it is more efficient to obtain these variables by calling [[DosGetInfoSeg]] instead of this function. However, applications written to the family API cannot depend on the availability of DosGetInfoSeg.
 
==Example Code==


===C Binding===
==Bindings==
===C===
<PRE>
<PRE>
typedef struct _DATETIME {  /* date */
typedef struct _DATETIME {  /* date */
   UCHAR  hours;            /* current hour */
   UCHAR  hours;            /* current hour */
   UCHAR  minutes;          /* current minute */
   UCHAR  minutes;          /* current minute */
Line 59: Line 32:
   USHORT  year;            /* current year */
   USHORT  year;            /* current year */
   SHORT  timezone;        /* minutes of time west of UTC */
   SHORT  timezone;        /* minutes of time west of UTC */
   UCHAR  weekday;          /* current day of week */
   UCHAR  weekday;          /* current day of week */  
} DATETIME;
} DATETIME;


#define INCL_DOSDATETIME
#define INCL_DOSDATETIME


USHORT rc = DosGetDateTime(DateTime);
USHORT   rc = DosGetDateTime(DateTime);
 
PDATETIME DateTime;      /* Address of date/time structure (returned) */
PDATETIME       DateTime;      /* Address of date/time structure
USHORT   rc;            /* return code */
                                    (returned) */
 
USHORT           rc;            /* return code */
</PRE>
</PRE>
This example gets the current time and date.
This example gets the current time and date.
Line 79: Line 48:
USHORT  rc;
USHORT  rc;


  rc = DosGetDateTime(&DateBuffer);        /* Date/Time structure */
rc = DosGetDateTime(&DateBuffer);        /* Date/Time structure */
</PRE>


===MASM===
<PRE>
DATETIME struc
  date_hours      db  ? ;current hour
  date_minutes    db  ? ;current minute
  date_seconds    db  ? ;current second
  date_hundredths db  ? ;current hundredths of a second
  date_day        db  ? ;current day
  date_month      db  ? ;current month
  date_year      dw  ? ;current year
  date_timezone  dw  ? ;minutes of time west of UTC
  date_weekday    db  ? ;current day of week
DATETIME ends
EXTRN  DosGetDateTime:FAR
INCL_DOSDATETIME    EQU 1
PUSH@  OTHER  DateTime      ;Date/time structure (returned)
CALL  DosGetDateTime
Returns WORD
</PRE>
</PRE>
==Example==
The following example obtains and prints date and time information. It then changes the system date to 5/10/1987 and prints the updated information.
The following example obtains and prints date and time information. It then changes the system date to 5/10/1987 and prints the updated information.
<PRE>
<PRE>
#define INCL_DOSDATETIME
#define INCL_DOSDATETIME
#include <os2.h>
#include <os2.h>


Line 105: Line 96:
   printf("rc is %d\n", rc);
   printf("rc is %d\n", rc);
  }
  }
</PRE>
===MASM Binding===
<PRE>
DATETIME struc
  date_hours      db  ? ;current hour
  date_minutes    db  ? ;current minute
  date_seconds    db  ? ;current second
  date_hundredths db  ? ;current hundredths of a second
  date_day        db  ? ;current day
  date_month      db  ? ;current month
  date_year      dw  ? ;current year
  date_timezone  dw  ? ;minutes of time west of UTC
  date_weekday    db  ? ;current day of week
DATETIME ends
EXTRN  DosGetDateTime:FAR
INCL_DOSDATETIME    EQU 1
PUSH@  OTHER  DateTime      ;Date/time structure (returned)
CALL  DosGetDateTime
Returns WORD
</PRE>
</PRE>


==Related Functions==
==Related Functions==
*  
*[[DosSetDateTime (OS/2 1.x)|DosSetDateTime]]


[[Category:The OS/2 API Project]]
[[Category:Dos16]]

Latest revision as of 17:45, 1 May 2023

Legacy Function Warning
It is recommended to use a newer replacement for this function.
Replacement: DosGetDateTime
Remarks: The function described here was part of the OS2 1.x API. It had been updated for modern OS/2 development, it is available at DosGetDateTime.

This call gets the current date and time maintained by the operating system.

Syntax

DosGetDateTime (DateTime)

Parameters

DateTime (PDATETIME) - output
Address of the date and time structure.

Return Code

rc (USHORT) - return
Return code description is:
  • 0 NO_ERROR

Remarks

The dayofweek value is based on Sunday equal to zero. The value of timezone is the difference in minutes between the current time zone and UTC. This number is positive if it is earlier than UTC and negative if it is later than UTC. For Eastern Standard Time, this value is 300 (5 hours earlier than UTC).

If the application is executing in the OS/2 environment, it is more efficient to obtain these variables by calling DosGetInfoSeg instead of this function. However, applications written to the family API cannot depend on the availability of DosGetInfoSeg.

Bindings

C

typedef struct _DATETIME {  /* date */
  UCHAR   hours;            /* current hour */
  UCHAR   minutes;          /* current minute */
  UCHAR   seconds;          /* current second */
  UCHAR   hundredths;       /* current hundredths of a second */
  UCHAR   day;              /* current day */
  UCHAR   month;            /* current month */
  USHORT  year;             /* current year */
  SHORT   timezone;         /* minutes of time west of UTC */
  UCHAR   weekday;          /* current day of week */ 
} DATETIME;

#define INCL_DOSDATETIME

USHORT    rc = DosGetDateTime(DateTime);
PDATETIME DateTime;      /* Address of date/time structure (returned) */
USHORT    rc;            /* return code */

This example gets the current time and date.

#define INCL_DOSDATETIME

DATETIME DateBuffer;
USHORT   rc;

rc = DosGetDateTime(&DateBuffer);        /* Date/Time structure */

MASM

DATETIME struc
  date_hours      db  ? ;current hour
  date_minutes    db  ? ;current minute
  date_seconds    db  ? ;current second
  date_hundredths db  ? ;current hundredths of a second
  date_day        db  ? ;current day
  date_month      db  ? ;current month
  date_year       dw  ? ;current year
  date_timezone   dw  ? ;minutes of time west of UTC
  date_weekday    db  ? ;current day of week
DATETIME ends

EXTRN  DosGetDateTime:FAR
INCL_DOSDATETIME    EQU 1

PUSH@  OTHER   DateTime      ;Date/time structure (returned)
CALL   DosGetDateTime

Returns WORD

Example

The following example obtains and prints date and time information. It then changes the system date to 5/10/1987 and prints the updated information.

#define INCL_DOSDATETIME
#include <os2.h>

main()
{
  DATETIME   DateTime;       /* Structure to hold date/time info. */
  USHORT     rc;

  rc = DosGetDateTime(&DateTime);     /* Address of d/t structure */
  printf("Today is %d-%d-%d; the time is %d:%d\n", DateTime.month,
         DateTime.day, DateTime.year, DateTime.hours, DateTime.minutes);
  DateTime.day = 10;
  DateTime.month = 5;
  DateTime.year = 1987;
  printf("The new date is %d-%d-%d; the time is %d:%d\n", DateTime.month,
         DateTime.day, DateTime.year, DateTime.hours, DateTime.minutes);
  rc = DosSetDateTime(&DateTime);    /* Address of d/t structure */
  printf("rc is %d\n", rc);
 }

Related Functions