how to get number of seconds


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to get number of seconds
# 1  
Old 11-27-2003
how to get number of seconds

How do I get the number of seconds since 1970, within a script, for the previous day at 23:59? I need this value to pass into a sql statement to cleanup records older than the previous day at midnight. It will be automated via cron so no hard coding allowed.

Thanks!
# 2  
Old 11-28-2003
This will return the number of seconds elapsed between January 1, 1970, and the specified time , ie yesterday at 23:59:00.
Code:
#!/usr/bin/perl
$now = time();
($sec,$min,$hour,@etc) = localtime($now);
$calc_secs = $now - (60*60*$hour) - (60*$min) - $sec - 60;
print "$calc_secs\n";

# 3  
Old 12-02-2003
Thanks to all for the perl help. I don't have perl on my servers so found a program on the net, compiled it and did this:

#setup the datetime variables to get last night at 23:59:59
cc=`date +"%C"`
yy=`date +"%y"`
mm=`date +"%m"`
dd=`date +"%d"`
hh=23
mi=59
ss=59

#assign the parameters to the variable
newtime="$mm $dd $cc$yy $hh $mi $ss"

#get the number of seconds since 1970 for tonight at 23:59:59
newseconds=`./seconds $newtime`

#get last night's seconds at midnight by subtracting one day from #midnight
let midnight=$newseconds-86400

#append the delete statement, with the system time, to the sql #script
echo "delete from oas_pvt_empty_order_data where expiration_date < $midnight;">> delete_contracts.sql
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting seconds to minutes

Hello everyone, I calculate in my bash script the different between two timestamps in seconds. The next step would be to get the difference in minutes, and there is my Problem:AnzahlUeberstunden=$(( $(date -d "$JAHR-$MONAT-$TAG $ArbeitEnde" +%s) - $(date -d "$JAHR-$MONAT-$TAG... (6 Replies)
Discussion started by: Chaos_Lord
6 Replies

2. Shell Programming and Scripting

Time in seconds on AIX 4.3.2.0

Hi to everybody again i Need your help, i wasting hours but can't find a solutuin for my Problem. I am not an expert with AIX script programming. I have a csh script and i need the time in seconds but since i have an old AIX the Option -%s doesnot exist with the date command. I seach in Google... (13 Replies)
Discussion started by: Nadielosabra
13 Replies

3. Shell Programming and Scripting

Compare fraction number and convert duration to seconds

Hi friends, I have a file with contents below: 01.m4a 00:14:45.82, 01.mp4 00:03:46.05, -659.770000 05.m4a 00:27:43.51, 05.mp4 00:27:45.10, 1.590000 06.m4a 00:11:39.73, 06.mp4 00:11:44.60, 4.870000 If 5th column value more than 3 or less than -3 then I should get its name (from first... (2 Replies)
Discussion started by: magnus29
2 Replies

4. UNIX for Dummies Questions & Answers

Sorting and wc -l w.r.t seconds

I have file with below data 00:00:00 00:00:00 00:00:00 00:00:01 00:00:01 00:00:01 00:00:01 00:00:01 00:02:01 00:02:01 00:02:01 so on till 23:59:59 I want count of seconds for each hour and minutes say for 00:00:00 its 3 and 00:00:01 its 5 and 00:02:01 its 3 and so on... (8 Replies)
Discussion started by: mirwasim
8 Replies

5. UNIX for Dummies Questions & Answers

Number of leap seconds

Is there a function call in std library or unit command that returns the number of current leap seconds? GG (4 Replies)
Discussion started by: NAVTime
4 Replies

6. Shell Programming and Scripting

Convert Seconds to hh:mm:ss

Hi All I need to convert a number of fields in a record from seconds to hh:mm:ss ( or possibly hhh:mm:ss ). I'm guessing awk is the way to go . File has multiple records and each record contains 101 fields - can awk handle that ? The seconds values will be in fields 3 - 101 and could be 0. ... (4 Replies)
Discussion started by: Mudshark
4 Replies

7. HP-UX

Ticks in seconds.

Hello all, Is there any thumb rule or aproximation of the equivalence in second of one tick? Thank you in advance. (1 Reply)
Discussion started by: mig28mx
1 Replies

8. UNIX for Dummies Questions & Answers

seconds to hh:mm:ss

Any sleek way to convert seconds to hh:mm:ss format . I know it can be done by mod and divide . Looking for a one liner if possible . Example 3600 seconds = 01:00:00 3601 seconds = 01:00:01 (2 Replies)
Discussion started by: akrathi
2 Replies

9. Shell Programming and Scripting

Get lines in 5 seconds

Hello everybody, how i can get how many lines are writed in a file in the last 5 seconds? For ezample i have 'file1' that is filled by a process automatically and i neet to know how many lines with the word 'EXACTO' were filled the last 5 seconds, can somebody help me? I try with: tail -f... (16 Replies)
Discussion started by: Lestat
16 Replies
Login or Register to Ask a Question