The pectoral and pelvic fins of the fish ancestor of amphibians had bones in them to support and move the fins. Those fish lived at the bottom of bodies of water, and they evolved legs and fingers to allow them to walk slowly on the bottom without having to swim. If you look at an amphibian such as a newt, you can see that it will use it legs to move slowly on the bottom looking for food. If it needs to move quickly, it will fold its legs along the side of its body and use its tail to swim.
That was probably what those fish with legs and fingers and toes did. They use the legs and fingers to move slowly on the bottom. The oldest fossils with fingers and toes are Ichthyostega and Acanthostega. They both lived around 370 million years ago. In contrast, Tiktaalic, which also have finger bones and toe bones, and which lived about 380 million years ago, only had fins, but no fingers or toes. That means the currently available evidence suggest that it took about 10 million years for fingers and toes to have evolved from a fish with finger and toe bones inside their fins. With more fossil finds in the future, perhaps we can determine more precisely when individual fingers and toes first evolved.
Although Acanthostega and Ichthyostega both have fingers and toes, Acanthostega is probably still a fish because an analysis of its anatomy suggests that its bones are not capable of supporting its weight on land. In contrast Ichthyostega is a bit more advanced and may have evolved the ability to walk on land. By about 330 million years ago, several different groups of amphibians, fully capable of walking on land, had already evolved. Therefore within a span of about 10 million years or less fish that walked on the bottom of water had evolved the ability to walk on land.