Given the state of the economy, there’s no shortage of stories about debt-saddled landlords delaying repayment of security deposits.

Take mine. After moving to San Francisco from New York in January, my husband and I tried for months to get in touch with our landlord and get our deposit back. Good tenants, we had always paid our rent on time, including the rent for the last two months of the lease when the apartment was vacant (we didn’t want a bad reference down the road), and left the apartment in perfect condition. Naturally, we expected to have no problem getting our deposit back.

But when we finally connected with the landlord at least four months later, she informed us that she simply didn’t have the money to pay us back. Her excuses — that many of the apartments in her buildings were now vacant and that she was renting our old place out for much less than we paid — left us scratching our heads (wasn’t she supposed to keep our money separate?) and wondering what we should do next.

Janet Portman, a lawyer and author of “Every Tenant’s Legal Guide” and an e-guide on getting security deposits back, said such situations were unfortunately pretty common these days, especially for tenants whose landlords are going into foreclosure or bankruptcy and may be broke.

Still, tenants aren’t without recourse. To get a security deposit back, Ms. Portman suggested first looking at what the laws in your state say about how long a landlord has to repay. Most states give landlords three to four weeks but some, like New York, give landlords a “reasonable” amount of time, generally assumed to be 30 to 60 days, as covered in this recent Real Estate Q&A. (Whether the landlords have to separate the money, put it in a bank and pay interest also varies by state.)

When landlords blow the deadline, Ms. Portman said, tenants should write them “a demand letter,” setting out all the facts, including that you paid a deposit of such and such amount, that you left owing no rent and that you left behind no damage beyond normal wear and tear. You should also mention that a reasonable amount of time has passed since you moved out and you would like your money repaid within a specified deadline. If that deadline passes, then you can take the landlord to small claims court.

In some states, like New York, you can file a complaint with the state attorney general first, before resorting to court. (Check out these other Real Estate Q&As on getting a deposit back in New York when a landlord won’t respond and when a new management company takes over a building).

But what you need to weigh before going to court, Ms. Portman said, is what going after your landlord is going to cost you in terms of time, effort and money vs. the likelihood you are going to get anything back (tenants in foreclosed buildings often are repaid before many other creditors, but not without putting in a lot of time and effort). “It may end up being more expensive to go after that deposit than it’s worth. Can you get blood out of a turnip?” Ms. Portman said.

In my case, according to Ms. Portman, what my landlord was doing was clearly illegal. Our story, however, has a happy ending. After the disturbing conversation with our old landlord, we touched base with a lawyer friend of ours who said he would start drafting our demand letter. Then we called the landlord to tell her we would be sending a letter soon unless she paid us the security deposit back in two installments over the next two months. The threat seemed to work, and two checks soon arrived in the mail.

If you’ve ever had trouble getting a security deposit back, what did you do? What tips do you have for making the process easier?