[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgi-list
Subject:    Re: [CGI] Dates ... again :)
From:       "$Bill Luebkert" <dbe () wgn ! net>
Date:       2000-09-28 6:25:55
[Download RAW message or body]

> Paul Ellsworth wrote:
> 
> Hello all,
> Ok, my problem:  I previously sorted via date only, but now it needs to be date AND \
> time.  How can I do this?  Here is an explanation of what I need to have, more in \
> detail ... 
> I have to have an entry of an image, and I need to get the date the image was \
> uploaded to the server from the file properties.  This I don't know how to do \
> either, but that isn't hard to find out.  Then, I need to be able to print that to \
> the database (just a text file), and be able to call that up, convert it into \
> seconds, so I can "sort $a <=> $b" it.  Currently, I have this: 
> my ($mon, $mday, $year) = split '/', $tempDate;                     # get the date \
> from the db (it is currently in MM/DD/YYYY) my $time = timelocal (0, 0, 0, $mday, \
> $mon-1, $year-1900);    # I guess this is getting the seconds of the time in \
> $tempDate $matches{$tempPicture}{DateInSeconds} = $time;                 # this \
> just puts it into results hash if ($time + 86400 * 14 > time) {                     \
> # This, I finally understand, sees if it is new (added in the last two weeks) print \
> "new"; } else {
> print "old";
> }
> 
> Another major problem is that images have already been added to the db, so I have \
> to have it compatible with MM/DD/YYYY also.  This is not that hard I guess.  Just \
> check to see if it's mm/dd/yyyy or mm/dd/yyyy/hour/minute/second.  Please note that \
> I have *no* idea how file-dates are kept when you retrieve them using Perl.

Please don't post in HTML.

First, it's easier to sort dates if you store them in the proper order:

	YYYYMMDDHHMMSSMMM  (with or without delims, but with leading 0's)

Then you can just sort the strings.
Many DBs also will retrieve dates in sorted order (don't ask me how, look it 
up somewhere) on proper SQL query.

Barring any of that, the best thing is to just convert to epoch time (which 
is the way I would store them in a DB anyway) and now they are just a numeric 
sort.  This is basically what you are doing above - converting to Epoch time.
To add time to the sort, just change those three 0's to $sec, $min, $hr where 
$sec, $min and $hr are also retrieved from $tempDate:

	my ($mon, $mday, $year, $hr, $min, $sec) = split '/', $tempDate;

Change them to 0 if undefined due to short date format.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--<  o // //      Mailto:dbe@wgn.net   http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
-----------------------------------------------------------------
To unsubscribe, send mail to "majordomo@jann.com" with "unsubscribe cgi-list"
in the body.

CalendarPlus v3.0 with JavaPlus is available NOW!
http://www.calendarplus.com/

The CGI Tips & Tricks website (and archive of the list) is located
at http://perl.jann.com/
-----------------------------------------------------------------


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic