Operating System - HP-UX
1829064 Members
2489 Online
109986 Solutions
New Discussion

Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

 
Vinesh Dhevcharran
Occasional Advisor

Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi

We have a library application which runs an Oracle database and the Unix scripts are written in csh. Some log files have the date & time as a string of numbers while some log files have the date as normal dd-mm-yyyy etc.

Does anyone know how I can convert the date string of numbers into DD-MM-YYYY HH:MI:SS


eg Batch Log
10117922575821 29651 p_manage_18 Library PTK01 locked in param
10117928490194 29651 p_manage_18 end 10117928494564 29651
p_manage_18 Library PTK01 unlocked

vs. equivalent Util/C/11 [some times not accessible]
23-01-2002 15:24:17 p_manage_18 Library PTK01 locked in
param 23-01-2002 15:34:09 p_manage_18 end 23-01-2002
15:34:09 p_manage_18 Library PTK01 unlocked

Many Thanks
Vinesh
7 REPLIES 7
Robin Wakefield
Honored Contributor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi Vinesh,

perl would be my choice:

# perl -e "@t=localtime(substr(shift,0,10));printf\"%02d-%02d-%04d %02d:%02d:%02d\n\",@t[3],@t[4]+1,@t[5]+1900,@t[2],@t[1],@t[0]" 10117922575821
23-01-2002 13:24:17

Rgds, Robin
Vinesh Dhevcharran
Occasional Advisor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi,

Well I have now discovered that we do not have perl. Where can I download this from or do you have an alternative. By the way, what format is this date string in?

Vinesh
Christian Gebhardt
Honored Contributor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

This is a little c-programm:

#include
#include
int
main (int argc, char *argv[])
{
time_t outdate;
char buffer[80];
int timestamp;

if (argc==1) timestamp=time(NULL); else timestamp=atoi(argv[1]);

strftime (buffer, 80, "%d-%m-%Y %H:%M:%S", localtime (&timestamp) );

printf ("%s\n", buffer );
return 0;
}

- copy and paste it in a file
- cc (you need an ANSIC-C-Compiler)
- rename the file "a.out" to e.g. uxtime2date
- run "uxtime2date 1011792257"
(without the last 4 digits)
- without an argument the actual date is displayed

I have attached an compiled version

Christian
Robin Wakefield
Honored Contributor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi Vinesh,

You should be able to download the Perl 5.6.1. depot from:

http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.6.1/

or any other mirrored site shown on the home page.

I am only familiar with the 10-digit date format, which is the number of seconds since 1st January 1970. That's why I truncated the 14-digit number that is in your logfile.

Rgds, Robin.
john korterman
Honored Contributor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi,
not precisely the format you want, but easy to achieve:

# TOTAL_NUMBER_OF_SECS=10117922575821

# REDUCED_NUMBER_OF_SECS=`echo $TOTAL_NUMBER_OF_SECS | cut -c1-10`

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


The output depends on the setting of your TZ variable (influences many other time functions).

Output on my system:
# 2002 Jan 23 15:24:17

regards,
John K.





it would be nice if you always got a second chance
inactive account
Frequent Advisor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Hi
Just to precise the date format: it is the french date format.
In France, we read the date starting with the day, then the month and finally the year.

doug hosking
Esteemed Contributor

Re: Converting a date string of numbers to DD-MM-YYYY HH:MI:SS

Vinesh, what HP-UX release are you asking about? In some, there is an (old) version of the perl binary in /usr/contrib/bin. In others, you might find it under /opt/perl/bin or similar.