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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
3 + 31 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 12:01:28 2024 UTC