php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55089 strptime() with UNIX timestamps
Submitted: 2011-06-30 10:12 UTC Modified: 2011-07-01 03:11 UTC
From: webmaster at raphaelmichel dot de Assigned:
Status: Wont fix Package: Date/time related
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-06-30 10:12 UTC] webmaster at raphaelmichel dot de
Description:
------------
It would be awesome to have a function in the standard library which either one working like strptime() but returning a UNIX timestamp or one converting an array like those returned by strptime() into a UNIX timestamp.

Test script:
---------------
<?php
function strptime_array_to_timestamp($array)
{
    if(!empty($array['unparsed']))
    {
        return false;
    }

    return mktime( isset($array['tm_hour']) ? $array['tm_hour']      : null, 
                   isset($array['tm_min'])  ? $array['tm_min']       : null,
                   isset($array['tm_sec'])  ? $array['tm_sec']       : null,
                   isset($array['tm_mon'])  ? 1+$array['tm_mon']     : null,
                   isset($array['tm_mday']) ? $array['tm_mday']      : null,
                   isset($array['tm_year']) ? 1900+$array['tm_year'] : null);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-01 03:11 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2011-07-01 03:11 UTC] aharvey@php.net
date_create_from_format() will give you a DateTime object, from which it's very 
easy to get a timestamp. As an added bonus, it behaves sensibly cross-platform, 
unlike strptime().

Closing won't fix.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Nov 30 18:04:14 2022 UTC