![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Happy Birthday to GNU | iBot | MySQL DevZone RSS | 1 | 06-11-2009 06:17 AM |
| calculation | aoussenko | Shell Programming and Scripting | 2 | 06-17-2008 09:09 AM |
| Birthday Mail Script | Kumarsharad | Shell Programming and Scripting | 1 | 06-13-2008 10:41 AM |
| Celebrate GnuPG's 10th birthday! | iBot | UNIX and Linux RSS News | 0 | 01-12-2008 04:10 PM |
| Happy birthday Linux | mib | News, Links, Events and Announcements | 1 | 06-30-2005 06:21 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Birthday Calculation
Hi I have a simple question.
Is there an easy way to read a date of birth from a file and calculate how old that person is based on today's date? And would I need the make sure the birthdates are enterered in a particular format? Thanks |
|
||||
|
You might have to take a look at datecalc script from the forum.
|
|
||||
|
A sample to calculate the age with a given date, adapt it to read the date from a file or if you have a different date format.
Code:
#!/bin/sh
echo -n "Enter the birthdate (mm-dd-yyyy): "
read bdate
bmonth=${bdate:0:2}
bday=${bdate:3:2}
byear=${bdate:6:4}
cdate=`date +%m-%d-%Y`
cmonth=${cdate:0:2}
cday=${cdate:3:2}
cyear=${cdate:6:4}
if [[ "$cmonth" -lt "$bmonth" ]] || [[ "$cmonth" -eq "$bmonth" && "$cday" -lt "$bday" ]]
then
let age=cyear-byear-1
else
let age=cyear-byear
fi
echo "Age = "$age
|
|
|||||
|
Quote:
Afraid it is supported by IEEE 1003.1:2004. Under shell command language reserved words section: Reserved words are words that have special meaning to the shell ..... The following words may be recognized as reserved words on some implementations (when none of the characters are quoted), causing unspecified results: [[ ]] function select ...... |
|
|||||
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|