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?
|
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 |
GNU date
Code:
# date +%Y%m%d -d "1 day ago" |
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 |
All times are GMT -5. The time now is 07:04 AM. |