During the Tokugawa shogunate, samurai increasingly became courtiers, bureaucrats, and administrators rather than warriors. With no warfare since the early 17th century, samurai gradually lost their military function during the Tokugawa era (also called the Edo period). By the end of the Tokugawa era, samurai were aristocratic bureaucrats for the daimyo, with their daisho, the paired long and short swords of the samurai (cf. katana and wakizashi) becoming more of a symbolic emblem of power rather than a weapon used in daily life. They still had the legal right to cut down any commoner who did not show proper respect kiri-sute gomen (斬り捨て御免?), but to what extent this right was used is unknown. When the central government forced daimyos to cut the size of their armies, unemployed rōnin became a social problem.
Try to answer this question if possible (otherwise reply "unanswerable"): When had samurai last been used in battle?
the early 17th century