UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2004, 08:09 AM
bh_perl bh_perl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 41 bh_perl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 37 m 34 sec
Reputation Power: 10
Send a message via Yahoo to bh_perl
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 ?

Reply With Quote
  #2  
Old March 4th, 2004, 03:44 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,406 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 10 h 17 m 19 sec
Reputation Power: 4080
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

Reply With Quote
  #3  
Old March 5th, 2004, 02:14 AM
papajohns's Avatar
papajohns papajohns is offline
perl virgin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Seattle, WA
Posts: 455 papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 14 h 18 m
Reputation Power: 13
please....perl is too much for this thing...

just do date +%m

%m will display month in numbers

Reply With Quote
  #4  
Old March 6th, 2004, 05:14 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
@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.

Reply With Quote
  #5  
Old March 6th, 2004, 05:28 AM
papajohns's Avatar
papajohns papajohns is offline
perl virgin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Seattle, WA
Posts: 455 papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level)papajohns User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 14 h 18 m
Reputation Power: 13
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

Reply With Quote
  #6  
Old March 6th, 2004, 08:08 AM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 45 m 36 sec
Reputation Power: 14
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...?

Reply With Quote
  #7  
Old May 22nd, 2004, 09:31 AM
mcq1 mcq1 is offline
mcq1
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: GA
Posts: 7 mcq1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old December 18th, 2012, 01:44 AM
makvaryar makvaryar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 makvaryar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 35 sec
Reputation Power: 0
Converting month name to Month number

try this out:

file_month=`ls -ltr <file_name> | awk '{print $6}' | sed 1q`
month_map="Jan 01\nFeb 02\nMar 03\nApr 04\nMay 05\nJun 06\nJul 07\nAug 08\nSep 09\nOct 10\nNov 11\nDec 12"
month_number=`echo $monthmap | grep $filemonth | awk '{print $2}' | sed 1q`
echo $month_number

Reply With Quote
  #9  
Old December 18th, 2012, 02:19 PM
aitken325i's Avatar
aitken325i aitken325i is offline
Providing fuel for space ships
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Mar 2004
Location: nr Edinburgh, Scotland
Posts: 14,360 aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)aitken325i User rank is General 42nd Grade (Above 100000 Reputation Level)  Folding Points: 10110 Folding Title: Novice Folder
Time spent in forums: 6 Months 1 Day 13 h 7 m 3 sec
Reputation Power: 3777
Last post was over 8.5 YEARS ago. Talk about thread necromancy . . . . .
__________________
The No Ma'am commandments:

1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
2.) It is wrong to be French
3.) It is O.K. to put all bad people in a giant meat grinder
4.) Lawyers, see rule 3
5.) It is O.K. to drive a gas guzzler if it helps you get babes
6.) Everyone should car pool but me
7.) Bring back the word 'stewardesses'
8.) Synchronized swimming is not a sport
9.) Mud wrestling is a sport

Reply With Quote
  #10  
Old March 26th, 2013, 04:15 PM
nagendra175 nagendra175 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 1 nagendra175 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 26 sec
Reputation Power: 0
month to integer

Two lines,

$month=date("m", time()); //returns string "03" for march
$month=intval($month); //makes it integer 3

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to convert month into numeric ?

Developer Shed Advertisers and Affiliates



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap