convert date to quarter

PHOTO EMBED

Fri May 26 2023 18:40:14 GMT+0000 (Coordinated Universal Time)

Saved by @vs #bash

# 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"
content_copyCOPY