LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2009, 11:08 AM   #1
onesikgypo
Member
 
Registered: Jun 2008
Posts: 56

Rep: Reputation: 15
Date Conversion : Month Name --> Number


Hi,

I have a script (Bash) that grabs a month from a specific file, however in that file it is listed as a name rather then a number (April May June etc.). Is there an easy way to convert this to a number (04 05 06..) - or is it a matter of creating a script that codifies each name to a number, i.e

if [ "$month" == "April" ]; then
monthn=04
elif [ "$month" == "May" ]; then
monthn=05
....

Any assistance would be greatly appreciated.
 
Old 04-28-2009, 11:26 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You could do something like:
Code:
monthn=`date -d "$month 1" +%m`
I arbitrarily chose the first day of the month.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl date conversion AndersT Programming 1 03-18-2009 04:26 PM
How to Find: last login information in terms of year-month-date avklinux Linux - General 7 03-14-2009 06:43 PM
Date command - month of year, blank padded? menator Programming 3 06-27-2006 06:00 AM
transform month number to month name in php ALInux Programming 1 11-09-2005 10:45 AM
Converting number to locale's abbreviated month name tsilok Linux - Newbie 4 10-25-2005 05:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration