jsuresh has asked for the wisdom of the Perl Monks concerning the following question:
I'm giving an excel sheet as an input to a perl file. In that, one of the column is date. The date format in that excel sheet is "21/03/2018" but when I upload it as input using perl, the format changes to "2018-03-21".
Another thing is , the format of the date in the input has "/" between them but after uploading it into perl, it changes to "-".
PleASE SUPPORT.
CODE
tHANKS, JPsub Date_Conversion_Julian{ my $origdate = shift; #my $date= Time::Piece->strptime($origdate$, '%Y-%m-%d'); #print $date->strftime('%d/%m/%Y'),"\n"; print "d:$origdate\n"; if ($origdate =~ /\//) { print "test\n"; if($dateformat eq 'mm/dd/yyyy') { my $dateparts = [ split /\//, $origdate ]; if (length($dateparts->[0])<2) {$dateparts->[0]= "0".$d +ateparts->[0];} if (length($dateparts->[1])<2) {$dateparts->[1]= "0".$ +dateparts->[1];} my ($mon,$mday,$year ); if(length($dateparts->[2]) > 2) { ($mon,$mday,$year)=(($dateparts->[0] - 1 ),$date +parts->[1],( $dateparts->[2] - 1900 )); } else{ ($mon,$mday,$year)=(($dateparts->[0] - 1 ),$date +parts->[1],( $dateparts->[2] + 100 )); } my ( $sec, $min, $hours ) = ( "00", "00", "12" ); my $julian_date = timelocal($sec, $min, $hours, $mday, + $mon, $year); $julian_date = ($julian_date / 86400) + 2440588; return $julian_date; } else { my $dateparts = [ split /\//, $origdate ]; if (length($dateparts->[0])<2) {$dateparts->[0]= "0".$ +dateparts->[0];} if (length($dateparts->[1])<2) {$dateparts->[1]= "0".$ +dateparts->[1];} #my @dateparts = $dateparts; #print Dumper \@dateparts; my ($mon,$mday,$year ); if(length($dateparts->[2]) > 2) { ($mday,$mon,$year)=(($dateparts->[0]),$datepart +s->[1] - 1,($dateparts->[2] - 1900)); } else{ ($mday,$mon,$year) =(($dateparts->[0]),$datepar +ts->[1] - 1,($dateparts->[2] + 100)); }
2018-06-12 Athanasius added code tags and removed paragraph tags from within code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date format
by thanos1983 (Parson) on Jun 11, 2018 at 13:34 UTC | |
by jsuresh (Acolyte) on Sep 06, 2018 at 08:33 UTC | |
by Corion (Patriarch) on Sep 06, 2018 at 08:52 UTC | |
by jsuresh (Acolyte) on Sep 06, 2018 at 11:04 UTC | |
by Corion (Patriarch) on Sep 06, 2018 at 11:11 UTC | |
by marto (Cardinal) on Sep 06, 2018 at 11:11 UTC | |
| |
|
Re: Date format
by runrig (Abbot) on Sep 06, 2018 at 17:56 UTC | |
|
Re: Date format
by poj (Abbot) on Jun 11, 2018 at 12:15 UTC | |
|
Re: Date format
by Anonymous Monk on Jun 12, 2018 at 16:10 UTC |