RE: [PHP] date frustrations

This is a discussion on RE: [PHP] date frustrations within the PHP General forums, part of the PHP Programming Forums category; There is probably a better way than this... But I always use EPOCH when I need to put something in ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-08-2003
Joe Harman
 
Posts: n/a
Default RE: [PHP] date frustrations

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-----
From: Shena Delian O'Brien [mailto:shena@darklock.com]
Sent: Tuesday, July 08, 2003 1:52 PM
To: php-general@lists.php.net
Subject: [php] date frustrations


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



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0