The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
gmoth gmoth is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 1
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...
  #2 (permalink)  
Old 02-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,719
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0