Check different date format

I'm using the follow script call to check a date stored in a variable as a string and store day, month and year in other three differents variables:

Code:
let testString = $gameVariables.value(1)
let testDate = new Date(testString);
$gameVariables.setValue(2, testDate.getDate());
$gameVariables.setValue(3, testDate.getMonth()+1);
$gameVariables.setValue(4, testDate.getYear()+1900);


It seems to recognize mm/dd/yyyy or yyyy/mm/dd formats, but how can I check for dd/mm/yyyy format?
Greetings
Try testDate.toLocaleDateString('en-GB')
Try testDate.toLocaleDateString('en-GB')

I tried these combinations, assuming var(1) = "I'm born on 12/05/2013" (random data, obv)

Code:
let testString = $gameVariables.value(1)
let testDate.toLocaleDateString('en-GB') = new Date(testString);
$gameVariables.setValue(2, testDate.toLocaleDateString('en-GB').getDate());
$gameVariables.setValue(3, testDate.toLocaleDateString('en-GB').getMonth()+1);
$gameVariables.setValue(4, testDate.toLocaleDateString('en-GB').getYear()+1900);

Code:
let testString = $gameVariables.value(1)
let testDate = new Date(testString);
$gameVariables.setValue(2, testDate.toLocaleDateString('en-GB').getDate());
$gameVariables.setValue(3, testDate.toLocaleDateString('en-GB').getMonth()+1);
$gameVariables.setValue(4, testDate.toLocaleDateString('en-GB').getYear()+1900);

Code:
let testString = $gameVariables.value(1)
let testDate.toLocaleDateString('en-GB') = new Date(testString);
$gameVariables.setValue(2, testDate.getDate());
$gameVariables.setValue(3, testDate.getMonth()+1);
$gameVariables.setValue(4, testDate.getYear()+1900);

but it returned me three "0" variables, but I guess I'm just failing to position your script in the right place...
I'll check it out when I get home and see if I can get it working for you.
Using a non-standard date format in JavaScript is kinda complicated. For input, you might need to parse it yourself with a regex and construct a date from the components. For output, you need to use Intl.DateTimeFormat. Here's an example for formatting a date in ISO format (yyyy-mm-dd):

JavaScript:
function formatDateTime(date) {
    // Using en-GB locale for the date because at least that isn't using mixed-endian
    var dfmt = new Intl.DateTimeFormat('en-GB', {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: false, timeZoneName: 'short'});
    var parts = dfmt.formatToParts(date);
    console.assert(parts[0].type === 'day' && parts[4].type === 'year', 'Unexpected date format?');
    [parts[0], parts[4]] = [parts[4], parts[0]];
    return parts.map(function({type, value}) {
        if(type === 'literal') {
            if(value === '/') return '-';
            else if(value === ', ') return ' ';
        }
        return value;
    }).reduce((prev, next) => prev + next);
};

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/check-different-date-format.124205/