Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Desktop
User Name
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.


  Search this Thread
Old 12-31-2007, 01:30 AM   #1
Registered: Dec 2006
Location: NOIDA, India
Distribution: Debian, SUSE, Fedora
Posts: 334
Blog Entries: 1

Rep: Reputation: 31
How do I calculate the number of days from a particular date using the <cal> utility?

How do I do it? I want to calculate. Is there any other method?
Old 12-31-2007, 02:26 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I don't think you can (easily) do it with "cal".

You *can*, however, do it with "date".

Specifically, with "date '+%j'"

The trick is:
1. Convert your "from" date to Julian format
2. Simply add/subtract the days you want
3. Convert back from Julian to normal MM/DD/YYYY (or whatever) format

'Hope that helps .. PSM
Old 12-31-2007, 03:16 AM   #3
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
GNU date
# date +%Y%m%d -d "1 day ago"
info date for more examples
Old 12-31-2007, 12:12 PM   #4
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Good point, ghostdog74 - thank you!

Deepumnit - in general, "date diff" problems usually involve "Julian dates" as part of the solution. But there are very often "convenience functions" that give you a simpler, more direct solution. Like the one Ghostdog74 suggested :-)

Anyway - I presume your question is completely answered.

Happy New Year .. PSM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate file age ? "File xy is 2 days 3 hours old" fluppi Linux - Software 5 06-03-2013 10:27 AM
Perl/bash - calculate date in future rose_bud4201 Programming 6 05-10-2009 05:59 AM
Calculate total number of mailq items a1phanumeric Linux - Newbie 1 11-15-2007 11:29 AM
Deleting files after x days from the latest date file sriramsreedhars Programming 8 03-03-2007 09:30 AM
Use Cal instead of date command - Bash Blackout_08 Programming 1 06-22-2006 11:39 AM > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 06:51 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration