converting unix date variable to gmt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting unix date variable to gmt
# 1  
Old 08-04-2006
converting unix date variable to gmt

Hi,
I have a ksh script which extracts files from a directory in the following format, eg:
10288.Job.rescheduled.1154647335

I need to extract the unix timestamp (eg 1154647335) and convert it to dd-mm-yyyy.

Can anyone suggest anything for this?

thanks. Smilie
# 2  
Old 08-04-2006
This should give you more information about it.
Code:
$ man localtime

I'm not sure if there's a standard utility for converting long -> date format.

If you have perl installed, this should do the trick:
Code:
$ cat x.pl
#!/usr/bin/env perl

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( 1154647335 );
$year+=1900; $mon++;

printf "%02d-%02d-%04d\n" , $mday , $mon , $year;


$ x.pl
03-08-2006

# 3  
Old 08-04-2006
Thanks for the reply. Perl must be installed, but wondering how I would call this from the Korn shell script?
# 4  
Old 08-04-2006
Code:
$ cat x.sh
x=$(./x.pl)
print Shell script says $x

$ ./x.sh
Shell script says 04-08-2006

# 5  
Old 08-04-2006
MySQL

Hi,
If this can help you

Code:
!/bin/bash
echo ' select left(from_unixtime(1154647335),10) "" ;' > time.txt 
mysql -u root -p "your_Pwd" <  time.txt


it is using from_unixtime function of Mysql to change ur unix timestamp in to date format u require. i have used left to extract date as it returns time also.
# 6  
Old 08-04-2006
Quote:
Originally Posted by chilli
Hi,
I have a ksh script which extracts files from a directory in the following format, eg:
10288.Job.rescheduled.1154647335

I need to extract the unix timestamp (eg 1154647335) and convert it to dd-mm-yyyy.

Can anyone suggest anything for this?

thanks. Smilie
if you're under Solaris:
Code:
echo '0t1154647335=Y' | /usr/bin/adb


Last edited by vgersh99; 08-04-2006 at 10:27 AM..
# 7  
Old 08-04-2006
unfortunately I don't have mysql or solaris installed on the server. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting String Date into UNIX Date

Hi, I have a string date to my unix script(sun solaris). I wanted to convert it into unix date so that I can use it in a conditional statement. Please see below: MyTest.sh -s 2018-05-09 suppdt=$1 # string date passed via arguement as 2018-04-09 curryr=`date '+%Y'` nextyr=`expr... (2 Replies)
Discussion started by: Saanvi1
2 Replies

2. Solaris

Convert GMT date and time to CST

I need away to convert the following GMT date and time value RAW_TME= 042720171530 "mmddccyyhhmm" to Localhost time. In this case it is in central time. Here is what I came up with but it does not look efficient: RAW_TME=042720171530 logmm=`echo $RAW_TME | cut -c1-2` logdd=`echo $RAW_TME |... (4 Replies)
Discussion started by: mrn6430
4 Replies

3. Shell Programming and Scripting

Date variable - 1 in UNIX

Hi, I have a variable which stores a date value in my script. let that be todays_date. This holds a date value which is based on some other calculation not relevant here. I need the value of todays_date-1..ie previous date to this value...is that possible? (12 Replies)
Discussion started by: siddharthmani
12 Replies

4. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

5. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

6. UNIX for Dummies Questions & Answers

How to get GMT Offset for a specific date?

How can I get GMT offset from EST for a particular date(not current date) in unix. For example, user enters date as: 2012-06-25D11:49:37, this is GMT. I have to calculate GMT offset from EST in unix for this input. Thanks in advance. -Steve (1 Reply)
Discussion started by: qwarentine
1 Replies

7. Shell Programming and Scripting

Using sed command replace date variable in unix

I need to use a shell script, using sed command how to replace date variable value in following format. 04/18/2012 11:38:55 Because the sed is treating the '/' as a parameter instead of the value of a variable, and hence there is the message as sed: command garbled: s/insert/04/18/2012... (9 Replies)
Discussion started by: jannusuresh
9 Replies

8. Shell Programming and Scripting

Converting the date format

Hi All, I am new to this forum. Could anyone help me to resolve the following issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1 5022090,4,1,6648,88,,,,,4/1/2011... (6 Replies)
Discussion started by: av_sagar
6 Replies

9. HP-UX

a simple way of converting a date in seconds to normal date

Hi all! I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date. Thanks (2 Replies)
Discussion started by: travian
2 Replies
Login or Register to Ask a Question