1832457 Members
2869 Online
110043 Solutions
New Discussion

calculation date

 
kamal_15
Regular Advisor

calculation date

hi all

i want to make a date calculation.
i have database informix with column include
the date (seconds from first january 1970).

when i get the value from this column .the result like that
------------------
856775871
845717763
938508910
938508912
-------------------
how can convert this integer values to date?

thankx
7 REPLIES 7
harry d brown jr
Honored Contributor

Re: calculation date

strftime

live free or die
harry d brown jr
Live Free or Die
john korterman
Honored Contributor

Re: calculation date

Hi,
hmm - looks like old files to me, but try this:
# NUMBER=856775871
# echo 0d$NUMBER=Y|adb

which gives the result shown below on my system. It will probably give a different result on yours as the TZ value is added to the time:
1997 Feb 24 10:17:51

regards,
John K.

it would be nice if you always got a second chance
Taulant Shamo
Frequent Advisor

Re: calculation date

Hi kamal ,

to change the valeus to date you can use the command one by one:

#ctime 856775871
Mon Feb 24 10:17:51 1997

#ctime 845717763
Sat Oct 19 11:36:03 1996

#ctime 938508910
Tue Sep 28 10:55:10 1999

#ctime 938508912
Tue Sep 28 10:55:12 1999

Than you can create a script to do it automatically for all values.


Taulant
Taulant Shamo
Frequent Advisor

Re: calculation date

Hi Kamal,

you can create the script changetime.sh
like below:
Example:
if you have the file data.txt in home directory like below:
------------------------------
#cat data.txt
856775871
845717763
938508910
938508912
---------------------------

---------------------------
#cat changetime.sh
#!/usr/bin/sh
while read line
do ctime $line | tee $HOME/dataout.date
done<$HOME/data.txt
---------------------------

#chmod 744 changetime.sh

---------------------------
Run the script:
#changetime.sh
Mon Feb 24 10:17:51 1997
Sat Oct 19 11:36:03 1996
Tue Sep 28 10:55:10 1999
Tue Sep 28 10:55:12 1999
-----------------------------

The script read line by line the file data.txt and run the command ctime for each line than the output is redirected to screen and even in the file dataout.date

---------------------------
#cat dataout.date
Mon Feb 24 10:17:51 1997
Sat Oct 19 11:36:03 1996
Tue Sep 28 10:55:10 1999
Tue Sep 28 10:55:12 1999
--------------------------------


Taulant

kamal_15
Regular Advisor

Re: calculation date

many thankx for response

but when i tryed command
-----------------
ctime 891712421
-----------------
error appear: sh: ctime: not found
why ctime dosen't work with me

i login with root user

thanks
Robert-Jan Goossens
Honored Contributor

Re: calculation date

Hi,

Create a directory.

# mkdir /tmp/time
# vi time.c
main(argc, argv)

int argc;
char **argv;
{
time_t foo;
foo = atoi(argv[1]);
printf("%s",ctime(&foo));
}
# cc time.c
this will create a file called a.out
# ./a.out 891712421
Sat Apr 4 19:53:41 1998

Regards,
Robert-Jan
A. Clay Stephenson
Acclaimed Contributor

Re: calculation date

The easist and most straightforward way to do this is via Perl's localtime() (or gmtime()) function.

perl -e 'print scalar localtime(856775871)'
If it ain't broke, I can fix that.