|
|
| Welcome to the Monastery | |
| PerlMonks |
Subtracting and Comparing Two Datesby mindful07 (Initiate) |
| on Jan 08, 2007 at 17:06 UTC ( [id://593632]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.mindful07 has asked for the wisdom of the Perl Monks concerning the following question:
I need your help with two issues I am having: How do you subtract two dates (both in the format of YYYYMMDD) to obtain the value in days? One date will always be local date and I'm using strftime("%Y%m%d", localtime(time) to obtain it. I do not have nor can I use the Time:Piece or Date:Calc modules at this time. The problem I am having is as long as its the same year (for example 20070108 - 20070101) my code will work fine giving me 7 days. But if I have 20070108 - 20061228 it will return an incorrect amount of days. My second issue is once I get the amount of days it doesnt appear that I'm able to compare it. I have a variable called $diff_days that returns 7. I then want to compare $diff_days > 15 or $diff_days = 15. Is that possible? What is the best way to handle that because I get a syntax error. Could you please provide examples since I am very new to Perl.
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||