It only applies to damage taken when attempting to cast the spell.  For a spell that's a standard action, that's only from opportunity and readied attacks that strike when they take that action.  Casting a spell with a longer cast time can be interrupted on another character's turn, but not from damage taken before the spell cast was started.