f_gettimedate
Use this function to get time and date information from a file or directory.
Date and Time Formats
The date and time fields are two 16 bit fields associated with each file/directory. The FAT format is used by default but any date/time format can be used; effectively this field is freely programmable.
The required format for the date for PC compatibility is a short integer ‘d’ (16 bit), such that:
Argument | Valid values | Format |
---|---|---|
Day | 0-31 | (d & 0x001F) |
Month | 1-12 | ((d & 0x01E0) >> 5) |
Years since 1980 | 0-119 | ((d & 0xFE00) >> 9) |
The required format for the time for PC compatibility is a short integer ‘t’ (16 bit), such that:
Argument | Valid values | Format |
---|---|---|
Two second increments | 0-30 | (t & 0x001F) |
Minute | 0-59 | ((t & 0x07E0) >> 5) |
Hour | 0-23 | ((t & 0xF800) >> 11) |
Format
int f_gettimedate (
const char * filename,
unsigned short * pctime,
unsigned short * pcdate )
Arguments
Argument | Description | Type |
---|---|---|
filename | The name of the file or directory. | char * |
pctime | Where to store the creation time. | unsigned short * |
pcdate | Where to store the creation date. | unsigned short * |
Return values
Return value | Description |
---|---|
F_NOERR | Successful execution. |
Else | See Error Codes. |
Example
void myfunc( void )
{
unsigned short t, d;
if (!f_gettimedate( "subfolder", &t, &d ))
{
unsigned short sec = (t & 0x001F) << 1;
unsigned short minute = ((t & 0x07E0) >> 5);
unsigned short hour = ((t & 0xF800) >> 11);
unsigned short day = (d & 0x001F);
unsigned short month = ((d & 0x01E0) >> 5);
unsigned short year = 1980 + ((d & 0xFE00) >> 9)
printf( "Time: %d:%d:%d", hour, minute, sec );
printf( "Date: %d.%d.%d", year, month, day );
}
else
{
printf( "File time cannot be retrieved!" );
}
}