LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 12-31-2007, 01:30 AM   #1
deepumnit
Member
 
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
paulsm4
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
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
GNU date
Code:
# date +%Y%m%d -d "1 day ago"
20071230
info date for more examples
 
Old 12-31-2007, 12:12 PM   #4
paulsm4
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
 
  


Reply


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


All times are GMT -5. The time now is 11:41 PM.

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