php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30545 strototime() returns -1 on @timestamp
Submitted: 2004-10-24 10:32 UTC Modified: 2005-06-30 09:08 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tightcode_nosp at m_hotmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.3.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tightcode_nosp at m_hotmail dot com
New email:
PHP Version: OS:

 

 [2004-10-24 10:32 UTC] tightcode_nosp at m_hotmail dot com
Description:
------------
The docs state:
"Because strtotime() behaves according to GNU date syntax, have a look at the GNU manual page titled Date Input Formats. Described there is valid syntax for the time parameter."
However the functionality described here:
http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html#SEC117
Which describes how to use seconds since Enoch, does not work with strtotime().
I have tried both strtotime('@timestamp') and strtotime('timestamp'). Both return -1. Please review the code below.


Reproduce code:
---------------
<?php
The correct way to do this according to the docs:
echo "Doc way: ".strtotime('@'.time());
Another try just to see if there is another way:
echo "Another way: ".strtotime(time());
?>

Expected result:
----------------
Doc way: (timestamp for current time)
Another way: (perhaps the same as above)

Actual result:
--------------
Doc way: -1
Another way: -1

I would expect there to be some way of doing this. If not according to the doc & syntax referenced in the online docs, at least "another way".

Thanks,

TightCode

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-24 13:02 UTC] derick@php.net
What's the point of doing this in the first place? strtotime() returns the number of seconds, so why do you want to use that as input parameter? This will not be added.
 [2004-10-24 14:04 UTC] tightcode_nosp at m_hotmail dot com
You say this will not be added... why was it removed in the first place ? According to the docs the functionality should exist.
To answer your question as to why, because it allows more flexibility for testing a date. It is my understanding that this function takes a string and tries to return a date from that string. Whether the date is expressed in text(Next Monday), iso standard timestamp(2004-04-04 04:04), or seconds since enoch(1147468399), the function shouldn't care. Why is it making an exception ? If it is fed a valid timestamp, -3600 to 2147468399 or whatever the two extremes are, it should pass that value right back through, not return -1.
Does that make more sense now that I have explained ? I am not always good at explaining things so thanks for being patient.

Thanks for your previous prompt response by the way,

TightCode
 [2005-06-30 09:08 UTC] derick@php.net
Actually, this was added in PHP 5.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC