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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: webmaster at raphaelmichel dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 11:01:28 2025 UTC