How does a node differentiate between an IPv4 and IPv6 datagram? [closed]

If the packet is received over Ethernet then the first thing is to look at the ethertype. 0x0800 is IPv4, 0x86DD is IPv6 and many more have been allocated: https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml

Then look at the version field in the packet, which are the first 4 bits.