tags:

views:

259

answers:

4

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 ??

+1  A: 

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.

MindStalker
Keep in mind that `substr` is zero based.
konforce
A: 

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.

Mike Sherov
+1  A: 
$us = preg_replace('#^(\d+)/(\d+)/(\d+)\s([\d:]+)\s([a-zA-z]{0,2})$#','$3-$2-$1 $4 $5', $date);
$timestamp = strtotime($date);
prodigitalson
A: 

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;
            }
assaqqaf