# Convert date to quarter
date_quarter() {
local date=$1
local year=$(date -d "$date" +%Y)
local month=$(date -d "$date" +%m)
month=${month#0} # Remove leading zero from month
local quarter=$((($month - 1) / 3 + 1))
local quarter_format="${year}Q${quarter}"
echo "$quarter_format"
}
# Example usage:
input_date="2023-09-02"
result=$(date_quarter "$input_date")
echo "Quarter format: $result" # "2023Q3"
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter