The Core Reporting API accepts a single
start date and end date in the request, and as such is completely customizable for the time periods you are requesting. But this means you will need to make at least two requests to compare two time periods. You will need implement the logic yourself to determine what determines the time period. This open source
Google Analytics Embed API demo shows how you can do such a comparison.
-Matt