•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,442 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,610 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 2172 | Replies: 4 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 22
Reputation:
Rep Power: 2
Solved Threads: 0
Hi all,
a=2007-05-10
b=2007-06-10
These are the two given dates and I need to compare.
The script should first compare years.If both are same or if a is lesser than b,it should print correct.If a is greater than b,then it should print error.Similarly for the dates(05 and 06).
No need to check for the months(10)
Regards
Dave Nithis
a=2007-05-10
b=2007-06-10
These are the two given dates and I need to compare.
The script should first compare years.If both are same or if a is lesser than b,it should print correct.If a is greater than b,then it should print error.Similarly for the dates(05 and 06).
No need to check for the months(10)
Regards
Dave Nithis
are you using ksh or bash? if so
The comparison parts you can do yourself.
set -A aArray `print "$a" | sed -e 's/-/ /'`
set -A bArray `print "$b" | sed -e 's/-/ /'`
# now ${aArray[0]} and ${bArray[0]} contain the year
# and ${aArray[1]} and ${bArray[1]} contain the day
# and ${aArray[2]} and ${bArray[2]} contain the monthThe comparison parts you can do yourself.
Last edited by masijade : Oct 26th, 2007 at 9:57 am. Reason: Oops, wrong var names in the comments
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
At the top of this forum is a fixed post to a tutorial. Read through some of that, try something out, if it doesn't work post your code and I'll help, but I'll not do it for you.
Last edited by masijade : Oct 26th, 2007 at 12:48 pm. Reason: typo
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
animations api apple asm assembly x86 programming hla demo blogger blogging c c++ ccna cocoa code coding competition compiler compilers computer debugging developer development evaluation flash framework gdata google high-performance innovation java languages microsystems multimedia news next object online open oriented planning platform practices programming python rss scripting software step sun tools tutorials web development xml
- Shell Programming (Shell Scripting)
- Shell Programming Project (Shell Scripting)
- Script to compare dates? (Shell Scripting)
- comparing dates using shell scripts (Shell Scripting)
- UNIX shell programming. Times function isn't working right (C++)
- Bourne / Bash Unix/Linux shell scripting tutorial (Shell Scripting)
- Zend PHP Certification (PHP)
- Good books on Shell Programming/Perl (Perl)
Other Threads in the Shell Scripting Forum
- Previous Thread: Creating a user in Linux without adduser/useradd
- Next Thread: problem with variable expansion in shell script



Linear Mode