|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
How to convert month into numeric ?
Hi,
Using UNIX command, Is there any possiblity how to convert "month into numeric ? ... example : "Jan" ==> 01 "Feb" ==> 02 Previously, I used CASE statement to convert them, but if you have any better ideas, could I shared with you ?
__________________
Thank you, bh_perl Swisscash .. Proven.. Investment Plan 7 Dollars Magic Proven.. Investment Plan |
|
#2
|
||||
|
||||
|
It's real easy in perl -- all you have to do is create a hash object. Are you allowed to use perl or not?
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
||||
|
||||
|
please....perl is too much for this thing...
just do date +%m %m will display month in numbers |
|
#4
|
|||
|
|||
|
@papajohns:
How do you solve it with a month different from the current one then? I think the original posting implied that he wants to find it for any month. M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#5
|
||||
|
||||
|
ah..ic...... if its programin he wants..then i guess a hash is good thing..although a simple shell script can do it too...just set variables...
jan=1, feb=2, so on....but from its context i understand it as he wants it to change month to a number at the unix command line |
|
#6
|
||||
|
||||
|
Here's a thought:
Code:
#!/bin/sh set `echo "Jan Feb Mar Apr May Jun Jul Aug Sep Nov Dec"` echo $3 This will output 'Mar'. Perhaps you could use this somehow...?
__________________
FreeBSD Admin Tips Tricks and Scripts |
|
#7
|
|||
|
|||
|
convert month to numeric
#!/bin/ksh
##---- function to convert 3 char month into numeric value ---------- convertDate() { echo $1 | awk -F"-" '{print $1,$2,$3}' | read day mm yyyy ## split the date arg typeset -u mmm=`echo $mm` ## set month to uppercase typeset -u months=`cal $yyyy | grep "[A-Z][a-z][a-z]"` ## uppercase list of all months i=1 ## starting month for mon in $months; do ## loop thru month list ## if months match, set numeric month (add zero if needed); else increment month counter [[ "$mon" = "$mmm" ]] && typeset -xZ2 monthNum=$i || (( i += 1 )) done ## end loop echo $day$monthNum`echo $yyyy | cut -c3-` ## return all numeric date format ddmmyyyy } ##---- main --------------------------------------------------------- convertDate 12-May-2004 ## function call with date argument |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > How to convert month into numeric ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|