UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #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: 5
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 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,337 Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 13 h 7 m 38 sec
Reputation Power: 674
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

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: 436 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 10 h 4 m 5 sec
Reputation Power: 8
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,969 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 1 Day 22 h 39 m 55 sec
Reputation Power: 184
@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: 436 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 10 h 4 m 5 sec
Reputation Power: 8
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 33 m
Reputation Power: 9
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
Reply

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


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway