Hi
How can I convert a time string like this:
30/7/2010
to a UNIX timestamp?
I tried strtotime()
but I get a empty string :(
Hi
How can I convert a time string like this:
30/7/2010
to a UNIX timestamp?
I tried strtotime()
but I get a empty string :(
You probably want to use http://us3.php.net/manual/en/function.strptime.php (strptime
) since your date is in a different format than what PHP might be expecting.
You could also convert it to a format that strtotime() can accept, like Y/M/D:
$tmp = explode($date_str);
$converted = implode("/", $tmp[2], $tmp[1], $tmp[0]);
$timestamp = strtotime($converted);
You're using UK date format.
Quick and dirty method:
$dateValues = explode('/','30/7/2010');
$date = mktime(0,0,0,$dateValues[1],$dateValues[0],$dateValues[2]);
PHP >= 5.3:
$var = DateTime::createFromFormat('j/n/Y','30/7/2010')->getTimestamp();
The PHP 5.3 answer was great
DateTime::createFromFormat('j/n/Y','30/7/2010')->getTimestamp();
Here is a < 5.3.0 solution
$timestamp = getUKTimestamp('30/7/2010');
function getUKTimestamp($sDate) {
list($day, $month, $year) = explode('/', $sDate);
return strtotime("$month/$day/$year");
}