The following code converts a string to a date (DateTime) object in PHP. The DateTime object provides a consistent method for handling dates in your PHP code.
Here’s another quick tip. If you have an integer value stored as a string and want to convert it to an “int” type, this tip is for you. You might want to use this if you’ve read an integer from a text file and therefore it was read in as a string value, but now you want to do a numeric comparison. Anyways, on to the tip. The following code converts a the string “25” to integer format.
So… instead, it’s recommended (by the people of the internet) that you use the “toString” method which will return a specific string for Array objects. The following code demonstrates this: