By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,799 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,799 IT Pros & Developers. It's quick & easy.

Date subtraction in Korn shell scripts

P: 2
I need to take a date, ie. 031708, and subtract one day from it. I have looked on the Internet to find a way to do this but all I have found is very complex and pretty old (from the late '90s). Is there any easy way to do this other than converting to Julian, subtracting one day, and then converting back to Gregorian? I'm not a Perl or C programmer and there is probably an easy way to do it in those languages. I'm not opposed to doing it in Perl but just don't know much about it.

Thanks,
Eric
Mar 17 '08 #1
Share this Question
Share on Google+
1 Reply

gpraghuram
Expert 100+
P: 1,275
I need to take a date, ie. 031708, and subtract one day from it. I have looked on the Internet to find a way to do this but all I have found is very complex and pretty old (from the late '90s). Is there any easy way to do this other than converting to Julian, subtracting one day, and then converting back to Gregorian? I'm not a Perl or C programmer and there is probably an easy way to do it in those languages. I'm not opposed to doing it in Perl but just don't know much about it.

Thanks,
Eric

Do you want to get the yesterdays date from todays date? or from any date you want to get the previous days date.
If your question is 1 then in Bash yu can do this using the date option like this
$ date --date='1 day ago' # past

If your question is 2 then you can write a small shell script to parse the date string into yy,mm,dd format and the deduct the day to get the previous days date

Raghuram
Mar 31 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.