As late as the organizers allow you to.

Usually for e-tickets, you can buy before 6-12 hours as latest.

For cash on delivery, it’s 2 days before the event.