JSFiddle - React, Tailwind, and code Playground
by Arvind Pal
JavaScript
function convertQuarterToDate(quarter) {
// Split the quarter string into quarter and year
const [quarterNum, year] = quarter.split('Q');
// Add "20" prefix to the year if it is less than 100
const fullYear = (parseInt(year) < 91) ? `20${year}` : `19${year}`;
// Construct the converted date format
const convertedDate = `${quarterNum}Q${fullYear}`;
return convertedDate;
}
// Example usage
const date1 = convertQuarterToDate("1Q20");
console.log(date1); // Output: 1Q2020
const date2 = convertQuarterToDate("3Q91");
console.log(date2); // Output: 1Q1991