Highlighted
Absent Member.
Absent Member.

Re: Use JavaScript to dynamically insert a button on a form


Hi Scott - Here's the function that I use to convert plain dates into more readable. The only piece missing is on the case where the date is in the prior week, currently I'm returning in MM/DD/YYYY (US-Centric) format, whereas if you have international users you would likely want to read their local setting and use that format instead:

function dateToText(dateStr) {

// Converts plain string dates into more human-readable dates using easily understandable terms like Today, Yesterday, etc...

if (!isDate(dateStr)) {

return dateStr;

} else {

var dateVal = new Date(dateStr);

var currentDate = new Date();

var startof_today = new Date(currentDate.toDateString())

var startof_yesterday = new Date(currentDate.toDateString())

startof_yesterday.setDate(startof_today.getDate()-1);

var startof_lastweek = new Date(currentDate.toDateString())

startof_lastweek.setDate(startof_today.getDate()-6);

if (dateVal >= startof_today) {

return "Today at " + dateVal.toLocaleTimeString();

} else if (dateVal >= startof_yesterday) {

return "Yesterday at " + dateVal.toLocaleTimeString();

} else if (dateVal >= startof_lastweek) {

var myDays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];

return myDays[dateVal.getDay()] + " (" + (dateVal.getMonth() + 1) + "/" + dateVal.getDate() + ") at " + dateVal.toLocaleTimeString();

} else {

return dateStr;

}

return dateStr;

}

}
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use JavaScript to dynamically insert a button on a form


Scott:

Another suggestion - use the SBM Javascript library API and jQuery.

jQuery tries very hard to take care of all the browser and browser-version dependent idiosyncrasies.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.