convert mmddyy date format to ccyyddd format?? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

convert mmddyy date format to ccyyddd format??

Shell Programming and Scripting


Tags
perl, perl shift, shift, shift perl

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-27-2006
Bhups Bhups is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 13 April 2007, 3:29 AM EDT
Posts: 23
Thanks: 0
Thanked 1 Time in 1 Post
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
Sponsored Links
    #2  
Old 09-27-2006
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 20 May 2014, 5:16 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts
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

Sponsored Links
    #3  
Old 09-27-2006
Bhups Bhups is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 13 April 2007, 3:29 AM EDT
Posts: 23
Thanks: 0
Thanked 1 Time in 1 Post
Power thanks alot bro...works fine:)

thanks alot bro...works fine
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert date format dba_frog Shell Programming and Scripting 3 04-29-2011 01:37 AM
Convert date to Unix format yahyaaa Shell Programming and Scripting 12 04-20-2011 09:31 AM
convert date format to mysql date format in log file hazno Shell Programming and Scripting 3 03-03-2009 08:05 AM
Convert Epoch time format to normal date time format in the same file rk4k Shell Programming and Scripting 3 11-19-2008 09:04 PM
Convert date format agathaeleanor UNIX for Dummies Questions & Answers 5 08-03-2008 10:25 PM



All times are GMT -4. The time now is 06:54 PM.