If you can, stay a few days or at least an overnight. If you have a car/rental take advantage of the freedom to drive there, stop in on gold rush towns on the way and explore at you leisure. Stay at the Yosemite Bug, one of my favorite hostels in the world and just 20 mins from the valley floor.
If you don't have a car, Amtrak trains runs packages where you can by train, go for the day or stay overnight:
http://www.amtrak.com/servlet/ContentServer?c=Page&pagename=am%2FLayout&cid=1241329087731 over 8 years ago
You can take a connecting Amtrak bus from the Ferry Building in downtown San Francisco (or from Fisherman's Wharf in San Francisco) to the Emeryville Amtrak (railway) station - from there you take a train to Merced (and then a connecting YARTS bus from Merced station to the Yosemite Bug Youth Hostel in Midpines - or all the way to Yosemite). You must make an advance reservation for this trip.(You book a bed at the Yosemite Bug youth hostel separately.) The entire trip takes at least 3 days; 1 day to travel from San Francisco to the Yosemite Bug youth hostel, at least 1 day to see Yosemite National Park (you take a YARTS bus into Yosemite National Park from the Yosemite Bug youth hostel) - plus 1 day to travel back to San Francisco (or south to Los Angeles instead), See: www.amtrak.com, www.yarts.com and www.yosemitebug.com over 8 years agoAnswered by davidflurrie via WorldNomads.com