What mileage counts as a self-employed business expense?

I need some clarification on calculating mileage expenses. If I drive from home to my W-2 job, then to my 1099 job, then home for the night, for which legs of the journey can I count mileage as a self-employed business expense?

I assume that if I travel directly from home to the location for my 1099 job and back home that I can count mileage for the whole trip. Is that correct?