I have a question regarding the date_parse_from_format() method:
$parsed = date_parse_from_format("Y d M H:i T", '2012 28 Nov 21:00 CET');
Returns associative array with detailed info about given date.
This will return an array with some date info. But is there any way to convert it to a unix timestamp?
Johan,
Heres an exact example of how to implement mktime into your scenario:
$parsed = date_parse_from_format("Y d M H:i T", '2012 28 Nov 21:00 CET');
$new = mktime(
        $parsed['hour'], 
        $parsed['minute'], 
        $parsed['second'], 
        $parsed['month'], 
        $parsed['day'], 
        $parsed['year']
);
echo $new; //returns: 1354136400
For future reference, you can use var_dump() or print_r() on an array to see how to access the nested values.
var_dump of $parsed
array (size=16)
  'year' => int 2012
  'month' => int 11
  'day' => int 28
  'hour' => int 21
  'minute' => int 0
  'second' => int 0
  'fraction' => boolean false
  'warning_count' => int 0
  'warnings' => 
    array (size=0)
      empty
  'error_count' => int 0
  'errors' => 
    array (size=0)
      empty
  'is_localtime' => boolean true
  'zone_type' => int 2
  'zone' => int -60
  'is_dst' => boolean false
  'tz_abbr' => string 'CET' (length=3)
                        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