The getdate() function is defined in the time.h header file. This function helps to converts the given date/time specifications pointed to by string into a structure 'tm' or into a broken-down time.
struct tm *getdate(const char *string); #where string is representation of a date or time
The getdate() function takes a single parameter as a pointer string which has the representation of date/time. The structure tm is allocated in static storage, and it will be overwritten by further getdate() function calls.
Parameter | Description | Required / Optional |
---|---|---|
string | pointer to a buffer(representation of a date or time) | Required |
The function converts the string representation of date/time into broken-down time and is stored in a tm structure. And the pointer to this structure is returned as the function output. To return error values this function uses an external variable or macro getdate_err.
Input | Return Value |
---|---|
if parameter | pointer to this structure |
#include <stdio.h>
#include <time.h>
int main()
{
struct date datm;
getdate(&datm;);
printf("Current system's date:\n");
printf("%d/%d/%d",
datm.da_day,
datm.da_mon,
datm.da_year);
return 0;
}
Output:
Current system's date: 18/4/2019
#include <stdio.h>
#include <time.h>
int main (){
struct date dt;
getdate(&dt;);
printf("Operating system's current date is %d-%d-%d\n"
,dt.da_day,dt.da_mon,dt.da_year);
return 0;
}
Output:
Operating system’s current date is 12-01-2012