How to retrieve the current timestamp?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to retrieve the current timestamp?
# 1  
Old 04-18-2011
How to retrieve the current timestamp?

I am doing this in my script ..
Code:
currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur"`

echo s $currenttimestamp

but this is how its shows
Code:
s 1 -------------------------- 2011-04-18-12.43.25.345071 1 record(s) selected.

How can I just get the timestamp 2011-04-18-12.43.25.345071

Just the timestamp ? Please suggest.

Thanks,
M

Last edited by Scott; 04-18-2011 at 05:26 PM..
# 2  
Old 04-18-2011
Code:
echo "s 1 -------------------------- 2011-04-18-12.43.25.345071 1 record(s) selected" |awk '{print $4}'
2011-04-18-12.43.25.345071

# 3  
Old 04-18-2011
hi..

this works if i just type it at the command..
but i need it as a variable ..
how do i do that ?

if I do
Code:
currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" |awk '{print $4}'`
echo s $currenttimestamp

it brings me this :
Code:
s connection


Last edited by Scott; 04-18-2011 at 05:26 PM..
# 4  
Old 04-18-2011
Code:
currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" |awk '{print $3}'`

# 5  
Old 04-18-2011
Thank you for the quick response ..but alas
I tried that as well
Code:
currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" |awk '{print $3}'`
echo currenttimestamp $currenttimestamp

I get this
Code:
currenttimestamp database

so, I tried print $0 and i get this
Code:
currenttimestamp SQL1024N A database connection does not exist. SQLSTATE=08003

Am not sure why its giving connection doesnt exist with "awk" string..

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 04-18-2011 at 05:28 PM..
# 6  
Old 04-18-2011
how about this way? hope it works
Code:
var=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur"
currenttimestamp=`echo $var |awk '{print $3}'`

This User Gave Thanks to yinyuemi For This Post:
# 7  
Old 04-19-2011
Thank you ..that worked !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. HP-UX

Comparing the timestamp of the file to current time

I have a file like this -rwxr-xr-x 1 rewq other 168 Jan 13 07:05 check_files.sh I want to compare (check_files.sh time) with the current time to see if its is older than 2 hours or not if it is not older than 2 hrs then do something.can someone help me on this?.I dont... (7 Replies)
Discussion started by: haadiya
7 Replies

3. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

4. AIX

Change specific (not current) date to timestamp

Hello to all. I work at AIX system without perl installed and I am restricted user, so I am limited to bash. In script that I am writing, I have to read line from file and transform date that I found inside to Unix timestamp. Line in file look something like this: Tue Mar 29 06:59:00... (5 Replies)
Discussion started by: Hyperborejac
5 Replies

5. Shell Programming and Scripting

Compare current time to timestamp on a file

I'm trying to compare 2 dates between current time and the timestamp on a file. The date format is mmdd Both return Apr 1 but when using if statement line 11: Apr 1: command not found error is returned #!/bin/sh log="DateLog" Current_Date=`date +%b%e` Filepmdate=`ls -l /file.txt |... (1 Reply)
Discussion started by: cillmor
1 Replies

6. UNIX for Advanced & Expert Users

In ksh find out the timestamp of current date?

Normally we can use %s to find out the time in second since 1970. But in my ksh, this format option is not available. Example- date +%s 1268103151 above script command won't work in ksh. Can you guys provide its equivalent ? (3 Replies)
Discussion started by: boy18nj
3 Replies

7. Windows & DOS: Issues & Discussions

How to log current timestamp inside a for loop in windows shell?

below is the output where i'm getting the same times tamp throughout the loop., where i'm expecting that to log the current time stamp.. C:\Users\ilango>for /l %i in (1,1,5) do echo for %i C:\Users\ilango>echo for 1 for 1 C:\Users\ilango>echo for 2 for 2 C:\Users\ilango>echo... (1 Reply)
Discussion started by: ilan
1 Replies

8. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

9. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

10. UNIX for Dummies Questions & Answers

retrieve timestamp associated with a file

Hi All, I am involved in a Datawarehousing project where my data files(ASCII text) are loaded on a Unix directory. When I do a Ls -l in Unix prompt i get a file listing along with the timestamp when these files were created/put on the server. I need to retrieve the timestamp associated with each... (2 Replies)
Discussion started by: 2nilotpal
2 Replies
Login or Register to Ask a Question