I have a date in this format "Wed, 26 Oct 2022 16:11:30 -1100", need to convert it to UTC time and in a format so it can be inserted into a MySQL database.
The date was pulled from an email using "$headerInfo->date;". I don’t see any way to receive the date any different.
Every way I try to do the conversion is painful and brute force.
Is there an elegant, or not painful way to do this?
TIA.
Been trying regex but it doesn’t handle converting the month into digits, then you have the UTC offset (time zone) to work with.
2
Answers
Parse the date/time string using DateTimeImmutable::createFromFormat, set the timezone to UTC then format it to MySQL’s datetime literal syntax
Demo ~ https://3v4l.org/G7RBG