From: Michael Paoli on
On May 24, 10:40 pm, Jack <junw2000(a)gmail.com> wrote:
> On May 24, 8:16 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote:
> > Jack wrote:
> > > I have a file containing timestamps from the date command, for
> > > example:
> > > Thu May 13 13:51:36 PDT 2010
> > > Wed May 12 11:51:36 PDT 2010
> > > Mon Fed 10 10:08:20 PDT 2009
> > > How to get the oldest timestamp? If I use a different "date" command,
> > > will it be easier to get the oldest timestamp?
> > You could use a complicated sort command. (untested)
> > sort -r -k6n,7 -k2M,3 -k3n,4 -k4.1n,4.3 -k4.4n,4.6 -k4.7n4.9 | head -1
> > Or you could save simpler time stamps with
> >    date +%Y%m%d%H%M%S
> If I have two timesamps obtained from " date +%Y%m%d%H%M%S ", how to
> compare them to get the older timestamp?

That:
$ date +%Y%m%d%H%M%S
won't always work.
Hints: timezones, daylight saving time / summer time

Hence, on
news:04e6a7df-4342-4596-bf0c-c8d1e8367ecd(a)y6g2000pra.googlegroups.com
I suggested:
> $ TZ=GMT0 date +'%Y-%M-%dT%H:%M:%S'
> 2010-05-25T03:05:54
> $ LC_ALL=C sort | head -1
As that date command as shown will work and sort (as shown)
consistently, as long as one's system times are correct, or at least
consistent.