Hello @Mark
Is it possible when using the “date-time” type that glide does a conversion from the regional format to the “us” format automatically (or at the limit to the ISO format, because I think that is to accept by new Date(…)).
Because my browser is in French, so the format is in dd / mm / yyyy except that if I send a Date column directly to YC (for example 15/8/2021) and I do a
Let x = new Date (date.value) I get an invalid date error, logical since js is in “us” format.
And if possible to have the same for the Array, because even worse if I make a date array (Split) from a Date column, the data is in “string” format and I have to take into account the format ( “Short, medium, long”) to be able to make a conversion.
I had to do a lot of code (and adjust the driver in the process) to try to convert the regional format to a usable date in JS and the reverse too
Unless I’m wrong, but the YC will run on the client side, so with the user’s regional format.
I have struggled with the same formatting issue since last week and working with arrays the code becomes more complex and larger unnecessarily.
Every datetime value has to be parsed to check if it’s a valid date (dd/mm/yyyy), if not, we have to split the date, take each day, month and year, move them and create a new valid format (mm/dd/yyyy or yyyy/mm/dd) to get a correct value to compare or calculate values based on dates.
Every time I found a Date array and I need to analyze it, the date format issue drives me crazy unnecessarily.
I can see now I’m not the only one crazy and with headaches due to it
it’s my code so far to sort and return a Date array (ascending) when a user has the date format dd/mm/yyyy .
It sorts the date and time at the same time and needs a date array of course to work.
In my case, I use a Hell Yes-Code version (from Mark’s version) where p8 parameter is the original (raw) Date Array:
p8.sort(function (a, b) {
// '13/9/2021 12:00:20'.split(' ') => ["13/9/2021", "12:00:20"]
let DTa = a.split(' '); DTb = b.split(' ');
// '13/9/2021'.split('/') => ["13", "9", "2021"]
let da = DTa[0].split('/');
let db = DTb[0].split('/');
let HMSa=DTa[1].split(':');
let HMSb=DTb[1].split(':');
// Hour
let ha = HMSa[0];
let hb = HMSb[0];
// Minute
let ma = HMSa[1];
let mb = HMSb[1];
// Secs
let sa = HMSa[2];
let sb = HMSb[2];
return da[2] - db[2] || da[1] - db[1] ||
da[0] - db[0] || ha - hb ||
ma - mb || sa - sb
});
// return the new sorted array
return p8
Not related to YC, but I recently had to deal with a similar challenge.
I had to write some code to import data from an external source, and the date formatting was all over the place. Specific issues:
Some dates were formatted as dd/mm/yyyy
Some dates were formatted as mm/dd/yyyy
Some dates were formatted as either of the above, but with trailing spaces which turned them into strings, which meant a new Date(date) call would fail.
The only thing I knew for certain was that all dates were supposed to be for the same month/year, and I knew which month/year that should be. So armed with that knowledge, I wrote the following function to validate and standardise them:
function check_valid_date(date, expected_month) {
var expected_month_index = LONG_MONTH_NAMES.indexOf(expected_month);
var data_type = typeof date;
switch (data_type) {
case "object": // It's probably a date
var checkdate = new Date(date);
if (checkdate.getMonth() === expected_month_index) {
// It's a valid date for the correct month, yay!
return checkdate;
}
break;
case "string":
date = date.trim();
var checkdate = new Date(date);
if (checkdate.getMonth() === expected_month_index) {
// It's a valid date for the correct month, yay!
return checkdate;
}
else {
// Check the delimiters, then swap the day/month bits
var delimiter = date.includes('/') ? '/' : '-';
var parts = date.split(delimiter);
checkdate = new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));
if (checkdate.getMonth() === expected_month_index) {
// It's a valid date for the correct month, yay!
return checkdate;
}
}
break;
default:
return undefined;
}
}
I need to parse and import this data on a daily basis, and so far the above seems to be working well (touch wood)
Do you think it’s possible to make a code that changes from 1 to a specific number based on the NOW() (date of form submission) the back to 1 when it gets to the max number?
Mínimum will always be 1 and Max is going to be dynamic. The YC gives a number from 1 to Max as Now changes. When it gets to the max number, it goes back to 1 and starts all over again.
Here is a small script that increments a number back based on the elapsed seconds.
Warning: Glide only updates every 10 seconds or more. So the precision is 10 seconds.
let Counter=parseInt(p1/10);
switch(Counter) {
case 0:
return p8[Counter]
break;
case 1:
return p8[Counter]
break;
case 2:
return p8[Counter]
break;
case 3:
return p8[Counter]
break;
case 4:
return p8[Counter]
break;
case 5:
return p8[Counter]
}
Hi
I am trying to use this code to replace date format from mm\dd\yyy to dd\mm\yyyy.
I am using your user system YC to determine what language the browser is and changing accordingly. https://Agent.manun2.repl.co