Handling file dates and time spans

The ScriptFTP scripting language does not have data types (as most scripting languages) and dealing with anything which is not plain text requires some kind of tricks. This happens with file lists as we have seen before, dates and time spans suffer the same limitation. This post covers how these data types are handled in ScriptFTP.

As we have only text strings to store a date, ScriptFTP uses a given text format. It is the following:


This means that the December the 1st 2016 at 8:30 pm is written this way:


If you use another format ScriptFTP will think it is not a date and any operation done with this variable will fail. As if you try to sum “abc” and “efd”. The result will be zero.

And what can you do with dates? you can, for example, determine if a given date is earlier than another:

 PRINT("date1 is more recent than date2")
 PRINT("date2 is more recent than date1")


The result of the script is the following (as you probably have guessed):

date1 is more recent than date2


And you can even calculate the time difference between two dates

$my_time_difference = $date1 - $date2
PRINT("there are ".$my_time_difference." seconds between date1 and date2")

The result is:

there are 55378664 seconds between date1 and date2


As you can see ScriptFTP handles time differences in seconds.

All these date/time operations (and others not shown here) are mostly used to compare file modification times against the current time or another file. The commands GETFILETIME and GETTIME (get current time) are used a lot in this context.

For example, if we want to delete from the FTP server the files older than a week:


# Substract a week (in seconds) from the current date,
# assign the result to another variable
PRINT("A week ago was ".$a_week_ago)
PRINT("Every file older than this will be deleted from the FTP server")
# Request the remote file list
# For each file in the current remote directory
# check if it is older than a week. If so delete it
FOREACH $remote_file IN $remote_file_list
 IF($file_last_modification_time < $a_week_ago)