I suppose it depends on what sort of submarine it was. The sub itself would be in no danger of structural failure since a hull designed to withstand up to 70 Bar of external pressure will have little problem dealing with 1 Bar of negative pressure.
No, the biggest danger will be the submarine’s inability to cool itself. Submarines are designed to operate in what effectively is a giant heat sink, and the sea water that it’s immersed in also acts as the medium by which excess internal heat is taken away from the machinery spaces.
Pull a sub out of the water and it starts getting hot very quickly, assuming that anything is running inside. This is the case by just pulling it out of the water, but imagine what the situation would be if it was in the vacuum of space, and there would be no convection or conduction to take away all the heat being generated inside. The vessel would only have direct infrared radiation as a way to lose heat, and this is several orders of magnitude less effective than what is achieved by conduction with water.
If the sub was diesel powered, and the main engines were immediately shut down (which they’d have to be since there’s no air to breathe in space), then the unfortunate sailors could very well survive for days on battery power if they were not too close to the sun. Put these same guys on a nuclear powered boat, and they would start cooking within hours as the heat exchangers that use sea water to cool the reactor suddenly lost their ability to function, and all those MWs of thermal energy had nowhere to go but soak into the hull of the boat.
Being slow cooked is not a nice way to die, so lets be glad that nobody has figured out how to teleport a fully manned submarine into space yet.
If not teleported back to Earth, the most likely event, not very long. Seals built to withstand ingress of water on the sub do not work very well at preventing escape of air into a vacuum from 15 Lbs per sq inch. Things would start leaking air very quickly and in just a few minutes, air pressure and oxygen levels would drop to an unsurvivable level.
An enterprising engineer might reconfigure and reroute some valves and pipes to vent the compressed air, normally used to blow ballast tanks, and other stored air at a controlled rate into the most airtight crew area. Crewmen could don rebreathers and take naps as the ‘corpsman’ administered tranquilizers. Oxygen generators would hold out for a while, but CO2 levels would not be a problem, because it would be escaping faster than it could be scrubbed out.
My guess is the best science fiction script would have them making it only a few hours to maybe a few days. They could make it longer if they could all cram into a small watertight compartment that was itself behind other watertight bulkheads. ie: a room within a room.
As they retreated into the bowels of the boat, and assuming they maintained control of the compressed air reserves into this compartment, they could put off the inevitable. We could also assume they could find some monkey-poop sealant and jam it into all the door seals and other leaking things. We also could assume, they had auxiliary heat of some kind either from batteries or the overheated nuclear reactor they shut down in the nick of time. With a little luck, they could survive a week or more until compressed air ran out.
In reality, our intrepid space submarine would probably just explode when the reactor went critical from lack of seawater for cooling. If a diesel sub, they would run out of oxygen before they could get the compressed air re-routed internally. No one could hear the screams.

Update, apparently I am wrong and the submarine would be just fine if teleported to space and will function perfectly well. My status has also been reduced to that of a total moron due to this post.
