FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 08-24-2008, 03:07 PM
"j t"
 
Default Command-line-interface (CLI) calculator to work out the difference between 2 dates

Hi all.

Does anyone have any suggestions for a command-line-interface (CLI)
calculator that can work out the difference between 2 (gregorian)
dates (i.e. that is calendar aware). My favourite cli calculator
("bc") doesn't seem to have any knowledge of the gregorian calendar.

Just to make it clear, I'd like to be able to type in:

20080824-20080724 and it would work out the answer as 31

(I'm happy to use any date format for input - I've only used ISO8601
as an example)

J :-)


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 08-24-2008, 03:54 PM
"Edward J. Shornock"
 
Default Command-line-interface (CLI) calculator to work out the difference between 2 dates

On Sunday 24 August 2008 18.07.59 j t wrote:
> Hi all.
>
> Does anyone have any suggestions for a command-line-interface (CLI)
> calculator that can work out the difference between 2 (gregorian)
> dates (i.e. that is calendar aware). My favourite cli calculator
> ("bc") doesn't seem to have any knowledge of the gregorian calendar.
>
> Just to make it clear, I'd like to be able to type in:
>
> 20080824-20080724 and it would work out the answer as 31


While I'm sure someone else will provide a much better way, I've used
something like

$ echo $(date -d 20080824 +%j) - $(date -d 20080724 +%j) | bc
31

..in the past.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 08-24-2008, 04:13 PM
Ron Johnson
 
Default Command-line-interface (CLI) calculator to work out the difference between 2 dates

On 08/24/08 10:07, j t wrote:

Hi all.

Does anyone have any suggestions for a command-line-interface (CLI)
calculator that can work out the difference between 2 (gregorian)
dates (i.e. that is calendar aware). My favourite cli calculator
("bc") doesn't seem to have any knowledge of the gregorian calendar.

Just to make it clear, I'd like to be able to type in:

20080824-20080724 and it would work out the answer as 31

(I'm happy to use any date format for input - I've only used ISO8601
as an example)


I think I'd write a simple Python/Perl script: convert date1 and
date2 to seconds past epoch, subtract, and divide by 86400.


--
Ron Johnson, Jr.
Jefferson LA USA

"Do not bite at the bait of pleasure till you know there is no
hook beneath it." -- Thomas Jefferson


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 08-24-2008, 04:14 PM
gary turner
 
Default Command-line-interface (CLI) calculator to work out the difference between 2 dates

j t wrote:

Hi all.

Does anyone have any suggestions for a command-line-interface (CLI)
calculator that can work out the difference between 2 (gregorian)
dates (i.e. that is calendar aware). My favourite cli calculator
("bc") doesn't seem to have any knowledge of the gregorian calendar.

Just to make it clear, I'd like to be able to type in:

20080824-20080724 and it would work out the answer as 31

(I'm happy to use any date format for input - I've only used ISO8601
as an example)


I Googled "date arithmetic", and found this,
http://www.walkernews.net/2007/06/03/date-arithmetic-in-linux-shell-scripts/


Can you adapt from that?

cheers,

gary
--
Anyone can make a usable web site. It takes a graphic
designer to make it slow, confusing and painful to use.
 
Old 08-24-2008, 04:25 PM
Ron Johnson
 
Default Command-line-interface (CLI) calculator to work out the difference between 2 dates

On 08/24/08 10:54, Edward J. Shornock wrote:
[snip]


While I'm sure someone else will provide a much better way, I've used
something like


$ echo $(date -d 20080824 +%j) - $(date -d 20080724 +%j) | bc
31


That a good idea. I never knew date(1) could do that. The problem,
though, is that it doesn't span years.


$ echo $(date -d 20090824 +%j) - $(date -d 20080724 +%j) | bc
30

Use delta from epoch, instead.
$ echo $[$(date -d 20090824 +%s) - $(date -d 20080724 +%s)]/86400|bc
396

--
Ron Johnson, Jr.
Jefferson LA USA

"Do not bite at the bait of pleasure till you know there is no
hook beneath it." -- Thomas Jefferson


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 09:32 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org