How to preserve the date and time information of files.

Search This thread

Hendrix7

Senior Member
Nov 18, 2023
102
25
The date and time attribute of files could get lost while transferring files. This is especially a problem with files that do not store any date and time information internally. Some formats like JPG and MP4 store the encoding date and time inside the file, and software usually gives them time-stamped file names, but that's not always the cast.

I learnt this the hard way in 2015, when I transferred a bunch of voice recordings created using "Smart Voice Recorder" from internal storage to MicroSD. I used that app because it had features that the pre-installed app did not have. It also recorded the audio into the ".WAV" format. (Side note: using a lossless format for mobile voice recordings is overkill. You waste lots of space for a trivial quality gain.)

After arriving on the MicroSD card, the date attribute of all those files was 2015-06-28. Even on the computer, all three types of dates (modification, creation, access) were 2015-06-28, and "Smart Voice Recorder" creates numerical file names which do not contain any time stamp, so there was no record of when those voice recordings were created.

Before moving files between the internal storage and MicroSD card using the on-device file manager, first test with one file whether the date attribute is retained. Loss of the time attribute seems to have been a long term problem on Android OS due to misconfigured file ownership, but appears to have been fixed in recent Android versions.

This also applies when adding files from a computer onto the smartphone through a USB cable (MTP). Since the smartphone's operating system is in control of writing the file, it might not retain the date and time information.

Another alternative is creating a file list using the ls your_directory_name -a -l -R >>filelist.txt (customizable command) into an Android terminal app such as "Android Terminal" by Jack Palevich or Termux.

If you connect your phone to the PC using a USB cable, it uses MTP (Media Transfer Protocol) to access the data. Early Android smartphones also supported direct mass storage access, so your phone would be treated as a USB stick, but this forced the internal memory of the smartphone to use the antique FAT32 file system for compatibility, since that file system is the common denominator across operating systems, and it could not be accessed simultaneously by the computer and by the smartphone.

If you copy or move files out of the smartphone using the file manager on your computer (Windows or Linux), the date and time is usually retained given that Windows or Linux (a desktop/laptop distribution of it) is in control of writing the file, and those operating systems retain the date and time stamp when writing files.

MTP has a bug where some files are listed with the date 1970-01-01, which is the beginning of the Unix epoch. This means the date and time stamp for that file has failed to load. If this occurs, move the files into a temporary directory using the on-device file manager, which will force MTP to relist the files and correctly show he dates and times. Then move them out of there using the computer file manager.

Fun fact: Windows Mobile in 2009 actually did retain the date and time when copying or moving between internal storage and MicroSD. So this is something Windows Mobile had over a decade before Android, at least non-modified Android.