f_settimedate


Use this function to set the time and date on a file or on a 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_settimedate (
    const char *     filename,
    unsigned short   pctime,
    unsigned short   pcdate )

Arguments

Argument Description Type
filename The file or directory. char *
pctime The creation time of the file or directory. unsigned short
pcdate The creation date of the file or directory. unsigned short

Return values

Return value Description
F_NOERR Successful execution.
Else See Error Codes.

Example

void myfunc( void )
{
    unsigned short ctime, cdate;
    ctime = (15 << 11) + (30 << 5) + (22 >> 1);      /* 15:30:22 */
    
    cdate = ((2002 - 1980) << 9) + (11 << 5) + (3);  /* 2002.11.03. */
    
    f_mkdir( "subfolder" );  /* Create directory */
    f_settimedate( "subfolder", ctime, cdate );
}