Is there a php func that does this:
$timestamp = get_timestamp_from_str('d/m/Y H:i', '10/10/2012 10:10');
strtotime() will use the USA version for '10/10/2012' wich is m/d/Y, but i have the day first.
For a particular case i can make my own parser, but the date format can change depending on the visitors local settings. However, i will always know the current format.
I had to insert this last paragraph so that this question is long and good enough for this portals question quality filter
Thank you
PHP | checkdate() Function The checkdate() function is a built-in function in PHP which checks the validity of the date passed in the arguments. It accepts the date in the format mm/dd/yyyy. The function returns a boolean value. It returns true if the date is a valid one, else it returns false.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
Return Values PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.
The PHP date() function convert a timestamp to a more readable date and time. The computer stores dates and times in a format called UNIX Timestamp, which measures time as a number of seconds since the beginning of the Unix epoch (midnight Greenwich Mean Time on January 1, 1970 i.e. January 1, 1970 00:00:00 GMT ).
Yes, it's called DateTime::createFromFormat()
.
You would use it as:
$datetime = DateTime::createFromFormat( 'd/m/Y H:i', '10/10/2012 10:10', new DateTimeZone('Something'));
$timestamp = $datetime->getTimestamp();
Just make sure your timezone string is in the list of supported timezones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With