set r to "July 4, 2021"
set {mm, dd, yyyy} to words of (short date string of (date r))
log (yyyy & mm & dd)
--> (*20210704*)
Yeah, that AppleScript is awful!

Note: The order of the variables will depend on your localization. Here in the US, itβs commonly MM-DD-YYYY, hence the order of mine.