Re: Follow up to mg106646 - Selecting a range of dates?
- To: mathgroup at smc.vnet.net
- Subject: [mg107227] Re: Follow up to mg106646 - Selecting a range of dates?
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sat, 6 Feb 2010 03:23:10 -0500 (EST)
- References: <hkgl2o$6sq$1@smc.vnet.net>
Hi,
> Given a list of date strings with each member in the list being in the
> format of "Thu Nov 19 12:09:23 GMT 2009", what is the best method of
> selecting matches between a date range?
>
> e.g., all data between November 1 2009 to November 8th 2009...
>
> I need to make sure this crosses year boundaries and such.
>
> My initial though is to convert the datestring into seconds since epoch and
> do a basic numerical comparison between two ranges.
basically I think that sounds like a very reasonable plan...
> I've tried:
>
> Cases[zz, _?(AbsoluteTime[{"12/01/2009", {"Month", "Day", "Year"}}] >=
> AbsoluteTime[#[[1]]] <=
> AbsoluteTime[{"12/02/2009", {"Month", "Day", "Year"}}]) &]
>
>
> where 'zz' is:
>
>
> {{"Tue Dec 01 00:03:57 GMT 2009", 7370}, {"Tue Dec 01 04:57:23 GMT 2009",
> 16179}, {"Mon Dec 07 20:50:04 GMT 2009",
> 8546}, {"Wed Dec 09 00:29:57 GMT 2009", 9017}}
And what is your question? I guess you would like to understand why the
code does not do what you want, but the reason is rather trivial: you
need a <= after the first AbsoluteTime to create a nontrivial condition.
Note that there is also Select, which fits your use case better than Cases:
Select[zz, (AbsoluteTime[{"12/01/2009", {"Month", "Day", "Year"}}] <=
AbsoluteTime[#[[1]]] <=
AbsoluteTime[{"12/02/2009", {"Month", "Day", "Year"}}]) &]
hth,
albert
- Follow-Ups:
- Re: Re: Follow up to mg106646 - Selecting a range of
- From: Jason Ledbetter <jasonbrent@gmail.com>
- Re: Re: Follow up to mg106646 - Selecting a range of