You can do that as long as your transaction is unconfirmed. Canceling = replacing your old transaction with a new one that sends the funds back to your address.
Confirmed by the system or by the client?
And how long does it take to confirm?
Thank you in advance!
A new block is mined on average once every 10 minutes so that's how long it takes for a transaction to be confirmed