Use the same external hard drive for two different Time Machine's?
Yes. Setup is easy.

Connect the drive to the first Mac directly (USB or whatever is fastest)
Add the drive in Time Machine Preferences
Use System Preferences, the menu bar or tmutil to make a backup.
Eject the drive from the first Mac once you have a couple backups completed.
Repeat the above steps for the second Mac.

Now when each Mac tries an hourly backup, if the drive is connected, it will update the backups there. (Make a new interval, expire any old intervals needed). If it’s not connected, you don’t get backups, but do get a warning every 2 weeks to reconnect an absent drive. It’s fine for one Mac to back up to multiple drives as well.

Now, you didn't ask for general advice, so take this with a grain of salt.

With two Macs, I often set up a three drive rotation. Rotate the drives once a month with one always off site is a good place to start if you don’t do backup rotations yet. You can safely remove that disk from system preferences so you are not nagged if you get those alerts.
I like naming drives Backup A, Backup B and putting a file on the root with the serial number of the drive, purchase date, warranty (if any) and date entering service in a text file.

So you'd have three drives like if you entered them into service today and the next three days.
Backup A 20200929
Backup B 20200930
Backup C 20201001
Also, last bit of &quot;advice&quot; that wasn't asked for - I put a drive on the shelf as soon as it fills. I don't erase them, just buy another inexpensive drive and then add it to the rotation. They only come off the shelf when I need to rebuild my index of what files are backed up to where with the excellent tool Backup Loupe.

https://www.soma-zone.com/BackupLoupe/