While mastering guitar is a lifelong pursuit, learning enough to play a few songs does not actually take too long. The first time you pick up a guitar, it will be extremely intimidating. There is a lot to learn about the strings, frets, and the notes they play, not to mention the very basics of handling the guitar correctly. However, within a couple of months, most beginner guitarists can be comfortable with a guitar and play a few basic songs.
The number one decider in how long it takes a person to learn electric guitar is how much time they put into it. While it is not a good idea when first starting out to play for several hours a day (which can lead to hand or wrist strain or injury), a beginner who puts in at least an hour a day will learn much more quickly than someone who only plays a couple days a week. Most of the basic guitar mastery is simply teaching your fingers the shapes they need to make, which can only be done with repetition.
Practicing smart is also important. Beginner guitarists should look up scales and chords and practice them with a metronome for the most efficient practice. Start out very slowly, and focus on getting each note just right each time. As you gain confidence, speed up the metronome a little bit each time.
A great chord exercise for beginners and experts alike is to take two difficult chords and switch between them in a rhythm, playing each one once. For a more advanced practice, add a finger picking pattern; for example, play the low E string with your thumb, then the G, B, and high E strings with your index, middle, and ring fingers. Looking up finger picking exercises will give you many different dexterity-building ways to practice finger picking and chords at the same time.
After a few basic chords are mastered in these ways, you can start learning songs. Look for simple songs that use beginner chords. Wild Thing is a great example; the verse uses only three easy chords, and the whole song only uses four. There is plenty of information online about good songs for a beginner to learn, look for one that you enjoy.
To learn a song, first look up the chords and learn them, then play along with the band. You do not have to use the same advanced strumming patterns as the guitarist, but just try to stay on tempo with them and change chords at the right time. Before you know it, you will have a few rock songs that you can play by yourself!
Getting to this point can take anywhere from a few weeks to a few months depending on how dedicated your practice sessions are. Remember that practicing correctly, with a metronome, is by far the quickest way to learn guitar. It might not feel as fun as fooling around with chords, but it is how to build mastery quickly.