The getdate() and setdate() functions are defined in the <dos.h> header file and are used to retrieve and modify the system date in DOS-based environments. These functions operate on a user-defined date structure containing the day, month, and year.
- getdate() retrieves the current system date, while setdate() updates the system date using a date structure.
- These functions are primarily supported in DOS/Turbo C compilers and are not available on modern Linux or standard C/C++ compilers.
setdate() Method
The getdate() function is defined in the <dos.h> header file and is used to retrieve the current system date. It stores the current date (day, month, and year) in a user-defined date structure.
- Retrieves the current system date and stores it in a date structure.
- Commonly used in DOS/Turbo C environments for date-related operations.
#include <dos.h>
#include <stdio.h>
int main()
{
struct date dt;
// This function is used to get
// system's current date
getdate(&dt);
printf("System's current date\n");
printf("%d/%d/%d",
dt.da_day,
dt.da_mon,
dt.da_year);
return 0;
}
Output:
Syntax
struct date dt;
getdate(&dt);
- Parameter: This function accepts a single parameter dt which is the object of structure date.
- Return Value: This method does not return anything. It just gets the system date and sets it in the specified structure.
Note: The <dos.h> header file used in this tutorial works only on dos-based systems and will not work on Linux-based systems.
setdate() Method
The setdate() function is defined in the <dos.h> header file and is used to set the system date. It updates the current system date using the values stored in a user-defined date structure.
- Sets the system date based on the values provided in a date structure.
- Commonly used in DOS/Turbo C environments for system date management.
#include <dos.h>
#include <stdio.h>
int main()
{
struct date dt;
// This function is used to get
// system's current date
getdate(&dt);
printf("System's current date\n");
printf("%d/%d/%d",
dt.da_day,
dt.da_mon,
dt.da_year);
printf("Enter date in the format (date month year)\n");
scanf("%d%d%d", &dt.da_day, &dt.da_mon, &dt.da_year);
// This function is used to change
// system's current date
setdate(&dt);
printf("System's new date (dd/mm/yyyy)\n")
printf("%d%d%d", dt.da_day, dt.da_mon, dt.da_year);
return 0;
}
Output:

Note: These programs are run in TurboC/C++ compiler
Syntax
struct date dt;
setdate(&dt)
- Parameter: This function accepts a single parameter dt which is the object of structure date that has to be set as the system date.
- Return Value: This method do not returns anything. It just sets the system date as specified.
