Hi,
The invoice number is not necessarily generated at the same time as the order number.
The order number is generated when an order is created.
The invoice number is generated based on the enabled statuses under the "invoice" column of the System>Order statuses menu.
By default, only the "confirmed" and "shipped" statuses are enabled so the invoice number is generated when the order status changes to "confirmed" or "shipped".
So, if you want the invoice number to be generated when the order is created, you can enable the "created" status under that column.
And in that case, the second solution I proposed will work like you want.
But you're right that if you use the second solution and the created status is not enabled under the invoice column, and the order is not confirmed / shipped on the same day it is created, the invoice number will be different from the order number.