Reputation: 192
HI, I have a problem parsing a date in php using strptime() as my system is running windows. I've also try to parse the date using strtotime() but not luck either because I'm using euro date format.
This is the date format I'm using 30/11/2009 11:00 am and I need to get the timestamp from it.
Any ideas how can I achieve this ??
Upvotes: 1
Views: 2092
Reputation: 1585
You can use this function:
function convert_datetime($str)
{
list($date, $time) = explode(' ', $str);
list($day, $month, $year) = explode('/', $date);
list($hour, $minute) = explode(':', $time);
$timestamp = mktime($hour, $minute, 00, $month, $day, $year);
return $timestamp;
}
Upvotes: 0
Reputation: 60403
$us = preg_replace('#^(\d+)/(\d+)/(\d+)\s([\d:]+)\s([a-zA-z]{0,2})$#','$3-$2-$1 $4 $5', $date);
$timestamp = strtotime($date);
Upvotes: 2
Reputation: 13427
dont use strtotime for this format... from the php doc:
The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now , or the current time if now is not supplied.
use one of the supplied methods in the other answers.
Upvotes: 0
Reputation: 14864
If your consistently using that date, just break up the date into multiple date pieces using substring.
$dayofmonth = substr($date,1,2)
$month = substr($date,4,2);
$year = substr($date,7,4);
etc, etc.
Upvotes: 2