Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date extraction using expr

Status
Not open for further replies.

christiniaroelin

Programmer
Sep 15, 2004
26
US
Hi,
I was facing problems with executing the following code:
#! /bin/ksh
export stamp=${stamp-"`"(expr $(date"+%m") -1)"'"}
echo $stamp

please advice on the right syntax.

Thanks
Christinia
 
Try this...
Code:
#!/bin/ksh

export STAMP=${STAMP-$(expr `date '+%m'` - 1)}
print $STAMP
Hope this helps.
 
Sam,
Thanks for your input..that worked fine..but i get the integer output. say instead of 06 the output is 6.i tried having a printf ..but wasnt successful.
Could you please advice on this

thanks
Christinia
 
Change it to...
Code:
#!/bin/ksh

typeset -Z2 STAMP
export STAMP=${STAMP-$(expr `date '+%m'` - 1)}
print $STAMP
That forces [tt]STAMP[/tt] to be two characters, zero filled.

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top