Treasuries have varying maturities from 3 months to 30 years. Investors buy them despite longer maturities because there are active secondary markets in which they can sell Treasuries to other investors anytime. Both stocks and bonds have secondary markets making them highly liquid.