You are not logged in.

#1 2012-04-24 20:20:55

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Comparing two dates+times [bash]

To compare two dates+times* in bash I have always used date +%s and compared the resulting strings.  Is there a better way to do it?  Thanks.

* As in "is date+time Y after date+time X?"


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#2 2012-04-25 16:02:53

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: Comparing two dates+times [bash]

@alphainer: I can't think of any other way. Personally, I'd advise to use a proper language with real data types (e.g. Python or Ruby) as soon as you need more than a handful date and time calculations.

Offline

#3 2012-04-25 16:46:52

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Comparing two dates+times [bash]

lunar wrote:

@alphainer

As opposed to whom? tongue

Most of the scripts I write don't warrant a real language.  Plus I like the portability I get with bash, even if some operations are pretty fugly.

Thanks though.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#4 2012-04-25 16:59:49

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: Comparing two dates+times [bash]

I'd say, anything beyond executing some scripts warrants a proper language, meaning real types, a proper module system, and a comprehensive standard library.  Bash is just not worth the hassle, not even with respect to portability. Python, Perl and Ruby are available on virtually any Linux system, either pre-installed, or in the package repositories. In turn, Bash isn't pre-installed on various Unix derivates.

Offline

#5 2012-04-25 18:49:03

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Comparing two dates+times [bash]

Years ago I wrote a bash script to build a thumbnail gallery webpage for a local directory structure of torrents.  For each torrent, it created the thumbnail of an image with the same name, scraped torrents to get seeders/leechers, parsed a text file of urls and added links below the image with special favicons for commonly linked sites.

That was a hassle, and I have been afraid to look at the script since I stopped using it.  But the page it produced was pretty sweet.

Most of the scripts I write are a bit more down-to-earth than that though.

Last edited by alphaniner (2012-04-25 18:50:02)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

Board footer

Powered by FluxBB