How can I create a gradient but I want it to go from one color to another like below
You can create a blend between two (or more) objects.
First create a solid filled rectangle for each end stop.
With both selected, go to Object → Blend → Make.
Then Object → Blend → Blend Options... and set spacing to "Specified Steps" and an appropriate number of steps.
There are two good answers here that propose using a blend, however if you want to match the colours of the jpeg you posted, you might want to expand the blend, and ungroup the rectangles, then you can select each rectangle and use the eydropper tool (I) to sample the exact colours from the raster image.