![]() |
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 |
| formatting date for different locales | Aeon | UNIX for Dummies Questions & Answers | 2 | 08-23-2007 12:39 AM |
| Date Formatting in Shell Script | Isiva | UNIX for Advanced & Expert Users | 2 | 07-10-2007 09:20 AM |
| Date formatting | knc9233 | UNIX for Dummies Questions & Answers | 8 | 01-16-2007 06:17 PM |
| date formatting | mgirinath | Shell Programming and Scripting | 4 | 07-08-2006 05:08 AM |
| Formatting date | radhika03 | Shell Programming and Scripting | 2 | 12-14-2005 02:56 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Formatting Date Variable (Pls help)
I have a situation where I am writing a shell script that will accept a date value it will then pass this date value to an Oracle stored procedure for processing.
I want to format the date into (01-SEP-08) before passing to the proc. I also want to make sure the value passed in is a date value if its not then i need to display an error message i.e. Invalid Date. I am new to this language and in language's like Java etc this would be a 1 liner just call a function pass in the date along with the format you want. Is this achievable with a Shell Script? Here is my code... #!/bin/ksh DATE=$1 if [ -z "$DATE" ] #I first check for null and format sysdate which is no problem then DATE=`date '+%d-%b-%y` echo $DATE else #This is where I want to format the arg variable how can I do that? echo $DATE fi Please help... |
|
||||
|
Try:
Code:
#!/bin/ksh
DATE=$1
if [[ -z "$DATE" ]] #I first check for null and format sysdate which is no problem
then
DATE=`date +%d-%b-%y"`
echo $DATE
else
#This is where I want to format the arg variable how can I do that?
DATE=$(echo "$1" | tr -s '[:lower:]' '[:upper:]')
echo $DATE
# test validity of date given
echo "
set pages 0
set feedback off
select 'OK'
from
dual
where
to_date($(printf "'%s'" $DATE),'DD-MON-YYYY') > to_date('01-JAN-1000','DD-MON-YYYY');
" | sqlplus -s jmcnama/555tgb | read okay
if [[ "$okay" = "OK" ]] ; then
echo "good date"
else
echo "bad date"
fi
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|