getdate() and setdate() function in C with Examples
getdate()
getdate() function is defined in dos.h header file. This function fills the date structure *dt with the system’s current date.
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 do not returns anything. It just gets the system date and sets it in the specified structure.
Program 1: Implementation of getdate() function
// C program to demonstrate getdate() method #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:

setdate()
setdate() function is defined in dos.h header file. This function sets the system date to the date in *dt.
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.
Program 1: Implementation of setdate() function
// C program to demonstrate setdate() method #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: This programs are run in TurboC/C++ compiler
Recommended Posts:
- wcsspn() function in C/C++ with Examples
- btowc() function in C/C++ with Examples
- SDL library in C/C++ with examples
- cauchy_distribution a() in C++ with Examples
- iswprint() in C/C++ with Examples
- iswgraph() in C/C++ with Examples
- wmemset() in C/C++ with Examples
- mbrtoc16() in C/C++ with Examples
- mbrtoc32() in C/C++ with Examples
- Pointers in C/C++ with Examples
- chdir() in C language with Examples
- Commonly used String functions in C/C++ with Examples
- asctime() and asctime_s() functions in C with Examples
- Understanding "volatile" qualifier in C | Set 2 (Examples)
- Methods to concatenate string in C/C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



