Hello jsuresh,

From the sample of code that you provide us you have only one return function on if none in else, also you are missing a few closing brackets on else.

Also why you are doing so many date calculations? There is no date module that can do everything for you?

What is exactly the input and output that you are trying to get?

Provide us a sample of compiling code so we can help you.

Update: After a lot of modifications on your sample code in order to make it able to compile I get the following error:

#!/usr/bin/env perl use strict; use warnings; use Time::Local; sub 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"; my $dateformat = "mm/dd/yyyy"; if ($origdate =~ /\//) { print "test\n"; if($dateformat eq 'mm/dd/yyyy') { 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 ($mon,$mday,$year ); if(length($dateparts[2]) > 2) { ($mon,$mday,$year) = ( ($dateparts[0] - 1 ), $dateparts[1], ( $dateparts[2] - 1900 ) ); } else{ ($mon,$mday,$year) = ( ($dateparts[0] - 1 ), $dateparts[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]), $dateparts[1] - 1, ($dateparts[2] - 1900) ); } else{ ($mday,$mon,$year) = ( ($dateparts[0]), $dateparts[1] - 1, ($dateparts[2] + 100) ); } } } } print Date_Conversion_Julian("21/03/2018"); __END__ $ perl test.pl d:21/03/2018 test Month '20' out of range 0..11 at test.pl line 42.

I had to add the missing module, missing curly brackets, convert your hash references to array elements and after that all your wrong hash reference points to array variables. Even after doing all that your code still does not compile as your calculations are wrong.

So try to explain us, you are trying to produce a date e.g. today (11/06/2018) then what? Are you trying to convert the (/) to (-) and push this date to excel? Are you trying to do some date calculations? Give us more information so we can try to help you.

Looking forward to your udpate, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Date format by thanos1983
in thread Date format by jsuresh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.