A bankruptcy filing can be accomplished in one day. You will need to decide whether you will have an attorney represent you in the bankruptcy or not. Since the revision of the bankruptcy code the obligations of the debtor have become significan, sometimes overwhelming. Give serious consideration to whether you can be attentive to all of the steps required to obtain a bankruptcy discharge.
Although it is possible to file a bankruptcy in one day there are many preliminary decisions that need to be made such as which is the appropriate chapter to file under. There also filing requirements that have to be met or the case may be dismissed. It would be imperative for you to have a consultation to review your options. You can get more information on the US Trustee's website as well.
You can file for bankruptcy right away which in turn puts a stay on the foreclosure but does not make it go away. You will have to deal with the non-payment of the mortgage through bankruptcy or deal with it afterwards.