I have started learning English. Currently, I can't understand the difference between the 'D' sound and the 'T' sound while listening to someone speaking or in audio. How can I learn how to distinguish between these two sounds?
Words that differ by only one sound, e.g. 'd' or 't' ("had" versus "hat"), are known as minimal pairs. So what you need is training on minimal pairs.
The English Club website has a list of minimal pairs for 'd' and 't' at the end of words: Minimal Pairs final /t/ and /d/.
John Higgins created a website with lots of minimal pairs:
Minimal pairs for English RP. The page most relevant to you is Consonants /t/ versus /d/. Update: The TalkTalk page is no longer available; page About the Higgins List of Minimal Pairs is hardly a replacement, unfortunately.
You can try to find YouTube videos about minimal pairs in English, but it may be hard to find videos that focus only on 'd' versus 't' (and I don't know which variety of English you are interested in).
You can also use Anki for minimal pair training: use one of the lists mentioned above, and find recordings of the words on Forvo.com.
See also the question How to train yourself to contrast heard sounds.
Note: My advice is mainly based on British English pronunciation. There are difference between American English and British English that affect the distinction between 't' and 'd', as Robert Columbia pointed out in a comment: "For example, in much of the US, the names "Patty" and "Paddy" are homophones."