The only way one can tell the case of a word - especially when it has the same ending as another case - is with context. The two best ways to look at the context in this instance would be to look for signal words or to think of the uses of each case. words are prepositions such as a/ab or e/ex which must take an ablative; or pronouns which are easier to identify such as 'mihi' (dative) vs 'me' (ablative).
By the uses of each case I mean how the dative case is less common and primarily used as an indirect object or is sometimes necessary with certain verbs like 'persuadeo' which take a dative as a direct object. Ablatives on the other are typically more common and have a variety of uses such as in an ablative absolute 'opere confecto' - when the work had been completed - or in time clauses for time when and time within which, or simply as agents in passives.