Connecting Tech Pros Worldwide Forums | Help | Site Map

hi problem in date

savanm's Avatar
Member
 
Join Date: Oct 2006
Location: chennai
Posts: 86
#1: Sep 28 '07
Hi all

Expand|Select|Wrap|Line Numbers
  1. my $temp;
  2. $temp=20070106;
  3. #####the first four digit is year next two digit is month nd the final two is day
  4. print $temp;
  5. $temp1=$temp;
  6. $temp1=~s/(.{4})(.{2})(.{2})/$1$2$3/g;
  7. print $temp1;
  8.  
in the above code result of $temp1 also the same...I need the o/p like this

Format 2007jan06...
If the i/p is 200070406...
then i need the o/p 2007april06

i need the above o/p with out using the perl module...

Navas.M

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Sep 30 '07

re: hi problem in date


Use a hash table or an array to define the months. An array works good because the months are numbers just like array indexes.

Expand|Select|Wrap|Line Numbers
  1. @months = qw(foo jan feb mar apr may jun jul aug sep oct nov dec);
  2. my $temp;
  3. $temp=20070106;
  4. #####the first four digit is year next two digit is month nd the final two is day
  5. $temp1=$temp;
  6. $temp1=~s/(.{4})(.{2})(.{2})/$1$months[$2]$3/g;
  7. print $temp1;
  8.  
'foo' is used just to pad the array because the array index starts at zero, and there is no month zero.
savanm's Avatar
Member
 
Join Date: Oct 2006
Location: chennai
Posts: 86
#3: Oct 17 '07

re: hi problem in date


Thanks Kevin... Code is working well...

Quote:

Originally Posted by KevinADC

Use a hash table or an array to define the months. An array works good because the months are numbers just like array indexes.

Expand|Select|Wrap|Line Numbers
  1. @months = qw(foo jan feb mar apr may jun jul aug sep oct nov dec);
  2. my $temp;
  3. $temp=20070106;
  4. #####the first four digit is year next two digit is month nd the final two is day
  5. $temp1=$temp;
  6. $temp1=~s/(.{4})(.{2})(.{2})/$1$months[$2]$3/g;
  7. print $temp1;
  8.  
'foo' is used just to pad the array because the array index starts at zero, and there is no month zero.

Reply