The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert date format YYYYMMDD to MM/DD/YYYY nasirgondal Shell Programming and Scripting 7 4 Weeks Ago 06:06 AM
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 11:03 AM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Dummies Questions & Answers 9 05-25-2007 05:26 AM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Advanced & Expert Users 1 05-24-2007 03:40 AM
how to convert from timestamp to date format in tcsh umen Shell Programming and Scripting 2 11-22-2005 12:51 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Dec 2005
Posts: 23
Question convert mmddyy date format to ccyyddd format??

hi,

for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format.
i checked the datecalc and other scripts but couldnt modify them to cater to my need...

The datecalc gives an output which i believe is the total days till that date, but i want to convert it in ccyyddd format

for exmple: for todays date:092706 (mmddyy) i want to convert it to "2006270" (ccyyddd), and similary say for for any other date.

thanks in advance!!!

regards,
Bhups
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
try this

Code:
scp
mm=`expr substr "$1" 1 2`
dd=`expr substr "$1" 3 2`
yyyy="20""`expr substr "$1" 5 2`"

ddd=`cal_days $yyyy $mm $dd`

echo "$yyyy$ddd"
Perl script
Code:
cal_days
#!/bin/perl
use Time::Local;
my $year=shift;
my $month=shift;
my $day=shift;
my $time = timelocal(0,0,23,$day,$month-1,$year-1900);
my $time1 = timelocal(0,0,0,1,0,$year-1900);
my $days = ( $time -$time1 ) / 86400;
printf("%.0f", $days);

Code:
$scp 092706
2006270
Reply With Quote
  #3 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Dec 2005
Posts: 23
Red face thanks alot bro...works fine:)

thanks alot bro...works fine
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0