There is an error as I cannot run this, can anyone help?
// Function to reformat dates to dd/mm/yyyy
colName = Column Dialog( "Select Date Column" );
reformatDateColumn = Function({dt, colName},
dt = Current DataTable();If( Column( dt, colName ) == Empty(),
Throw( "The selected column does not exist in the current data table." );
);
// Function to identify and reformat the date
formatDate = Function({date},
// Check for different date formats and convert to dd/mm/yyyy
If( Contains( date, "/" ),
// Check if date is in dd/mm/yyyy or mm/dd/yyyy format
If( Substr( date, 3, 1 ) == "/",
// Assume dd/mm/yyyy format
date,
// Assume mm/dd/yyyy format and convert to dd/mm/yyyy
Concat( Word( 2, date, "/" ), "/", Word( 1, date, "/" ), "/", Word( 3, date, "/" ) )
),
// Handle mmddyyyy, ddmmyyyy, yyyymmdd, or yyyyddmm format
If( Length( date ) == 8,
// Check if first two digits form a valid month or day
If( Num( Substr( date, 1, 2 ) ) > 12,
// Assume ddmmyyyy format
Concat( Substr( date, 1, 2 ), "/", Substr( date, 3, 2 ), "/", Substr( date, 5, 4 ) ),
// Assume mmddyyyy format and convert to dd/mm/yyyy
Concat( Substr( date, 3, 2 ), "/", Substr( date, 1, 2 ), "/", Substr( date, 5, 4 ) )
),
If( Length( date ) == 8,
If( Num( Substr( date, 1, 4 ) ) > 999, // Check if first 4 digits form a valid year
// Check if the next two digits form a valid month or day
If( Num( Substr( date, 5, 2 ) ) > 12,
// Assume yyyyddmm format
Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) ),
// Assume yyyymmdd format and convert to dd/mm/yyyy
Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) )
),
// If not a valid year or format, return the original date
date
),
// If the date length is not 8, return the original date (invalid format)
date
)
)
)
);
//Create the UI with buttons to trigger the functions
New Window( "Data Processing Tools",
V List Box(
// Button to reformat date column
Button Box( "Reformat Date Column",
// Open a dialog to select the date column
colName = Column Dialog( "Select Date Column" );
// Call the function to reformat the selected date column
reformatDateColumn( Current Data Table(), colName );
)
)
);