06-16-2008
Perl date conversions
Is there a perl date conversion that will convert this type of date:
2008/100:01:56:10.000
to this type of date:
2008 04 09 01 56 10 000
I am using this right now:
sub jd2date
{
$space=" ";
$zero="0";
my ($jd) = @_;
if (($jd<1) || ($jd>782028))
{
print "julian day out of range\n";
return 1;
}
use integer;
$standard_jd=$jd+2400001;
use integer;
$temp1 = $standard_jd + 68569;
use integer;
$temp2 = (4*$temp1)/146097;
$temp3 = $temp1 - ((146097 * $temp2 + 3) / 4);
use integer;
$year = 4000 * ($temp3 + 1) / 1461001;
use integer;
$temp4 = $temp3 - 1461 * $year/4 + 31;
use integer;
$month = 80 * $temp4 / 2447;
use integer;
$day = $temp4 - 2447 * $month / 80;
use integer;
$temp5 = $month / 11;
use integer;
$month = $month + 3 - 12 * $temp5;
use integer;
$year = 100 * ($temp2 - 49) + $year + $temp5;
if (length($month)==1)
{
use integer;
$tempmonth=$zero . $month;
}
else
{
use integer;
$tempmonth=$month;
}
if (length($day)==1)
{
use integer;
$tempday=$zero . $day;
}
else
{
use integer;
$tempday=$day;
}
use integer;
$wholedate=$year . $space . $tempmonth . $space . $tempday;
return $wholedate;
}
It works with a date like this:
2008/100:01:56:10.000
to this type of date:
2008 04 09 01 56 10 000
but gives the wrong date for this type of date:
2008/009:01:56:10.000
I am getting this date:
2007 13 09 01 56 10 000
I think it might be the julian date conversion, but I can't figure it out.
Is there a way to convert this date without doing a julian date conversion?
Thanks.
Allyson
8 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
I have script that runs based on time variables passed in the command line. The first command argument is a timer, in seconds, of how often to execute a certain loop in the script. The second command argument is the end time of the script, in military time. Below is an example of the command line:... (1 Reply)
Discussion started by: Nysif Steve
1 Replies
2. Shell Programming and Scripting
I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date.
$file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z
really appreciate any help.
thanks
mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies
3. Shell Programming and Scripting
I have over 800 scripts (Korn and Perl) wrote on a Unix platform (Solaris) that I need to covert to a Linux platform (Redhat). All the path's and binaries need review. Are there any tools out there that would simplify or assist me with this conversion? (3 Replies)
Discussion started by: soupbone38
3 Replies
4. UNIX for Advanced & Expert Users
I was reading these 2 articles. Why does the wikia one think :e ++ff=dos? Or am I just misunderstanding it?
:e ++ff=unix
:e ++ff=dos
File format - Vim Tips Wiki
Managing/Munging Line-Endings with Vi/Vim | Jeet Sukumaran (1 Reply)
Discussion started by: cokedude
1 Replies
5. Shell Programming and Scripting
Hi All,
Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl?
(To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies
6. Shell Programming and Scripting
Hi All,
what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case
week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies
7. Shell Programming and Scripting
$beginDate = substr(DateCalc("today", "-7Days"),0,8);
This fetches the date 7 days back
Can I fetch the date before 7 years from todays date in Perl using same syntax
Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies
8. UNIX for Advanced & Expert Users
Sorry if this is in the wrong area. I am not sure where to put this question.
HD manufacturers usually use the 1000 scale for measuring their HD capacity instead of 1024 which is way more common with computers. What would 750 GB on the 1000 scale convert to on the 1024 scale and how would you... (1 Reply)
Discussion started by: cokedude
1 Replies