I find some of the information required to answer this question is covered in the inquiry into the loss of the Philadelphia , which can be read in the Naval documents related to the United States wars with the Barbary powers This court was held on June 29, 1805 and the record contains testimony of many of the crew as well as Bainbridge himself.
From the testimonies we can gather some information concerning the time involved (all emphasis mine):
At half past 11 when within a league and a half from Tripoli, seeing no
probability of preventing the chase from getting into port, we ceased
firing and hauled off shore, then having eight fathoms water. We had not
one more than two cables length before we suddenly shoaled...
So the Philadelphia was grounded at 11:30 A.M., according to Bainbridge.
After having triedy every expedient that could be thought of to
contribute to our relief, and exerting ourselves to the utmost from
the time of our grounding until half past four p. m. in
indeavoring to get the ship aﬂoat and at the same time in resisting
the enemy, but ﬁnding all hopes of the ﬁrst vain, and not being able
to bring our guns to bear to effect the latter, I called a council of
officers to consult them on the subject of a further resistance or the
necessity of surrendering to the enemy. Upon a deliberate
consideration of our situation, it was the unanimous opinion that it
was impossible to get the ship 06, and that all further resistance
would be but unnecessarily exposing men in a situation where neither
perseverance nor fortitude would be of any beneﬁt to our Country or
ourselves; and it was unanimously agreed that the only thing left for
us to do was to surrender to the enemy, which was accordingly done,
after drowning the magayine, and destroying as many articles as
possible, that might be of use to the enemy —
So grounded at 11:30 AM, efforts to free her until 4:30 PM, The Philadelphia was grounded for at least 5 hours. Since the only untried procedures to free the ship involved towing (and the Philadelphia was alone, as the Vixen had been sent elsewhere), and the placement of an anchor by boat some distance away to pull the ship clear in a process known as kedging. The court asked if this process had been considered on several occasions, and the response was that the ship had no boat which could carry the anchor safely, and that the enemy held the position necessary to place the anchor. So while the enemy ships were present, the Philadelphia was out of options.
The Wikipedia article on Bainbridge says this, (with a source listed as The Pirate Coast, Richard Zachs):
if he had chosen to wait until high tide his ship would have floated
free of the sandbank.
We can make an assumption here, with information from NOAA:
High tides are 12 hours and 25 minutes apart and are separated by a
low tide. So low tide must come 6 hours and 12.5 minutes after one
high tide and before the next.
So after the grounding of 5 hours by Bainbridges testimony, the next high tide could have been as little as an an hour away. (But we don't know if, without the ability to place a kedge anchor, or get a tow, that the Philadelphia could have cleared herself even then.) As pointed out by @Peter Diehr in comments, tides in the Mediterranean are generally less pronounced than those in ocean regions (measured in centimeters, according to this source)
We can assume then that the grounding lasted at least 6 hours before the pirates were able to free the ship.
Another source The Encyclopedia of the Wars of the Early American Republic, 1783–1812: A ...
edited by Spencer C. Tucker (pg 1005) states this:
Several days later following a storm the Tripolitans refloat it;they
also recover its guns. They tow it into Tripoli Harbor, where they
begin repairs with the intention of adding this powerfull warship to
So when was the Philadelphia refloated, answers seem to range from 'the next high tide' to "several days later". The several days later source seems to have better detail, I lean towards it.
I found another entry in the Naval Documents listed above(1), which discusses time involved before the ship was refloated. A letter from Bainbridge to Tobias Lear, the US Consul General in Algiers, while still in captivity (8 Feb 1804), details when and how the ship was freed:
About 40 hours after we struck, a gale from the westward raised the
waters on this coast and made such a sea as ﬂoated the ship off; we
were not Gods to forsee the wind and sea, and if we had, our fate must
have been the same, for in far less time she would have been cut to
pieces; and verily believe that nothing less than the assistance of
the Elements could have got her off.
This confirms the storm source, and pretty much settles the issue.
As to refit time, I have found little conclusive information yet. Most of the ships guns had been thrown overboard, so salvage dives had to be performed to retrieve them. The foremast had been cut away as well. The ship reappears anchored in Tripoli harbor at the time of the Decatur action. Some entries mention that she was
...anchored in the harbor as a gun battery.
implying repairs may have not been completed to the point of making the ship fully seaworthy. The same source which mentions the several day delay, indicates the raid was taken to destroy the Philiadelphia because
once repaired by the Tripolitans, it would shift the naval balance in
Again this implies repair were never fully completed before the ship was destroyed in the raid on February 16, 1804. The answer to the second part of the question,when was it
added to the Bey's Pirate fleet?
is, never. It was destroyed before ever leaving Tripoli Harbor again.