Operating System - HP-UX
1837523 Members
3794 Online
110117 Solutions
New Discussion

Re: Converting AMTIME1970 date to Human

 
SOLVED
Go to solution
Nabil_2
Advisor

Converting AMTIME1970 date to Human

Hi,
I have a text file that contains a field for date or time in seconds since AM 1970.
for exmaple

209515656 test1 test2 test3
209518655 test3 test2 test5
209523456 test1 test3 test1
.
.
.


How can I hadle this date format. I need to be able to convert this date column in this text file to this format
2002/07/15 for example.

I need to be able to do this thru out the file which contain over 60,000 lines...

I need this so I can upload this file into a mysql databse table ..

Do you think a simple script could do the trick or do you have any other suggestions

Thanks for any help

-Nabil
8 REPLIES 8
Scott Van Kalken
Esteemed Contributor

Re: Converting AMTIME1970 date to Human

In this case, I'd just write a script to process the date.

I did a similar thing with perfview data (when exported) as it's exported in UTC
Nabil_2
Advisor

Re: Converting AMTIME1970 date to Human

Hi,
Thanks for the reply ..Do you think you can help me with this...
Do you think a normal Ksh will do the conversion quick or need to get into compiling some C code ....

James R. Ferguson
Acclaimed Contributor

Re: Converting AMTIME1970 date to Human

Hi Nabil:

# TS=209515656
# echo "${TS}=Y" | adb

...would yield, 1974 Dec 15 02:44:22

Regards!

...JRF...
Rodney Hills
Honored Contributor
Solution

Re: Converting AMTIME1970 date to Human

A perl script could handle the job-

open(INP,"open(OUT,">newfile");
while() {
chop;
if (/^(\d+)\s/) {
$sec1970=$1;
@a=localtime($a);
$new=sprintf "%4.4d/%2.2d/%2.2d",$a[5]+1900,$a[4]+1,$a[3];
s/$sec1970/$new/;
} else {
die "line does not begin with a number!";
}
print OUT $_,"\n";
}

This will create a newfile with the date (in seconds) converted to yyyy/mm/dd format.

-- Rod Hills
There be dragons...
Nabil_2
Advisor

Re: Converting AMTIME1970 date to Human

Thanks James,
But what is adb ?? I don't think I have this bin file..
Also how do I plug the date after conversion back into the field and change it again to this format YYYY/MM/DD


Thanks again...

Rodney Hills
Honored Contributor

Re: Converting AMTIME1970 date to Human

Oops, the following line needs to be change-
@a=localtime($a);

to-
@a=localtime($sec1970);

-- Rod Hills
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: Converting AMTIME1970 date to Human

Hi (again) Nabil;

Sorry, that timestamp was probably in decimal, so make the example:

# TS=209515656
echo "0d${TS}=Y" | adb

...which is 1976 Aug 21 18:47:36...

It's up to you to reformat it, which is why Rodney's solution using perl is nice.

'adb' stand for "absolute debugger'. Have a look at its man pages. It's 'usr/bin/adb' and has many, many uses.

Regards!

...JRF...
Nabil_2
Advisor

Re: Converting AMTIME1970 date to Human

Thank you all for replying and helping me ...Rodney solution was just Awesome ..This little Perl script did exactly what I was looking for ....I will put it to the true test tomorrow...

Thanks a bunch Rodney ..This answer deserves a lot more than 10 points...