On Wednesday 09 July 2003 01:51, Shena Delian O'Brien wrote:
[snip]
> Well I gradually figured out that the date format output by filemtime()
> was not an acceptable natural language date format. filemtime() was
> fetching dates with a dash - ex. 07-08-2003. strtotime() was making
> incorrect timestamps because it doesn't read dates with dashes formatted
> that way.
What version of PHP are you using? And what exactly is the code that you're
using?
filemtime() returns a _unix timestamp_ and will asort() as is.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
A woman without a man is like a fish without a bicycle.
-- Gloria Steinem
*/
Ahh, you're right! I had a rogue:
$date = date("m-d-Y", filemtime($fn));
in there. :) Thought I got rid of all of those in testing... my
organization has a standard date format and it must be dashes instead of
slashes, and of course it has to be month, day, year!
Jason Wong wrote:
> On Wednesday 09 July 2003 01:51, Shena Delian O'Brien wrote:
>
> [snip]
>
>
>>Well I gradually figured out that the date format output by filemtime()
>>was not an acceptable natural language date format. filemtime() was
>>fetching dates with a dash - ex. 07-08-2003. strtotime() was making
>>incorrect timestamps because it doesn't read dates with dashes formatted
>>that way.
>
>
> What version of PHP are you using? And what exactly is the code that you're
> using?
>
> filemtime() returns a _unix timestamp_ and will asort() as is.
>
The php manual says filemtime() returns a unix timestamp (does it do the
same in a Windows environment?). I tried the following snippet, and it
seemed to work as expected:
$dlist = array();
$handle = opendir($dir);
while ($file = readdir($handle))
$dlist[$file] = filemtime($file);
asort($dlist, SORT_NUMERIC);
foreach($dlist as $name => $mtime)
printf("%-30s\t%s\t%s\n", $name, $mtime, date("m/d/Y G:i",$mtime));
hth
Kurt Milligan
Shena Delian O'Brien wrote:
> Ok so on a web application I needed to list the files in a directory,
> ordered by last modified date.
>
> I was pulling them out in an array, fetching the filemtime() for each
> file, and trying to order them by that date. I was using asort() to sort
> the files in an array so they'd list chronologically.
>
> Well that wasn't working as planned. Files were getting out of order. I
> figured asort() could have been having trouble ordering dates
> numerically, so I tried strtotime() on the dates first, and ordered the
> files by unix timestamp.
>
Date: Tue, 8 Jul 2003 17:14:38 -0400
There is probably a better way than this... But I always use EPOCH when
I need to put something in order... You can then just write a function
to interperate the date when it need to be readable.... Hope that makes
sense
joe
-----Original Message-----
Sent: Tuesday, July 08, 2003 1:52 PM
To: php-general@no-spam
Ok so on a web application I needed to list the files in a directory,
ordered by last modified date.
I was pulling them out in an array, fetching the filemtime() for each
file, and trying to order them by that date. I was using asort() to sort
the files in an array so they'd list chronologically.
Well that wasn't working as planned. Files were getting out of order. I
figured asort() could have been having trouble ordering dates
numerically, so I tried strtotime() on the dates first, and ordered the
files by unix timestamp.
That didn't work either. I did a date() on the unix timestamp fetched by
strtotime() and found that the dates were coming out inaccurately. 2003
was being changed to 2013, etc.
Well I gradually figured out that the date format output by filemtime()
was not an acceptable natural language date format. filemtime() was
fetching dates with a dash - ex. 07-08-2003. strtotime() was making
incorrect timestamps because it doesn't read dates with dashes formatted
that way. Apparently asort() reads dates the same way strtotime does.
I think this is kind of perverse... in order to fix it I had to do an
ereg_replace("-","/",$date) in order to change the filemtime() date
format to one properly readable by strtotime and asort.
*sigh*
Am I the only one who has noticed this? Is this something that can be
corrected in PHP? (Perhaps the dates fetched by filemtime() etc can be
changes to be formatted in a way that is acceptable to other date()
functions??)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php