Date to second since 1970


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Date to second since 1970
# 1  
Old 06-16-2008
Date to second since 1970

Hello,
I have found a piece of code which converts seconds elapsed since 1970 for an input date. Can anyone please explain a little bit the code below:

Code:
#!/bin/bash
# function to reproduce UNIX time() value
second()
{
set -- $(TZ=GMT date '+%Y %m %d')
local y=$1 m=1$2 d=1$3
((m-=103, d-=101, m<0 && (m+=12, --y)))
((d+=(m*153 + 2)/5+y*365+y/4-y/100+y/400-719468))
echo $((d*86400))
}


Last edited by Yogesh Sawant; 06-16-2008 at 02:22 AM.. Reason: added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

4. Shell Programming and Scripting

Write Linux script to convert timestamps older than 1.1.1970 to 1.1.1980

I am having problems because some of my files have timestamps that are earlier that 1.1.1970, the Unix start of time convention. So I would like to write a script that finds all files in home folder and subfolders with timestamps earlier than 1.1.1970 and converts them to 1.1.1980. I... (3 Replies)
Discussion started by: francus
3 Replies

5. AIX

The result of Jan 01 (1970) by last command

Dears, My boss asked me to record the login information on AIX server, so I used "last" command to get i want. But it is so strange when i get a record the login date is Jan,01 1970 (as attached picture). does anyone know what happen? Thanks and Regards, (6 Replies)
Discussion started by: Zack.Chiang
6 Replies

6. 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

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

9. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

10. UNIX for Dummies Questions & Answers

days since 1970

How can I get the syatem to give me the days since 1970 (as seen in the shadow file)? (4 Replies)
Discussion started by: 98_1LE
4 Replies
Login or Register to Ask a Question
libapache2-mod-perl2-2.0.7::docs::api::APR::Date(3pm)	User Contributed Perl Documentation  libapache2-mod-perl2-2.0.7::docs::api::APR::Date(3pm)

NAME
APR::Date - Perl API for APR date manipulating functions Synopsis use APR::Date (); # parse HTTP-complient date string $date_string = 'Sun, 06 Nov 1994 08:49:37 GMT'; $date_parsed = APR::Date::parse_http($date_string); # parse RFC822-complient date string $date_string = 'Sun, 6 Nov 94 8:49:37 GMT'; $date_parsed = APR::Date::parse_rfc($date_string); Description "APR::Socket" provides the Perl interface to APR date manipulating functions. API
"APR::Date" provides the following functions and/or methods: "parse_http" Parse HTTP date strings $date_parsed = parse_http($date_string); arg1: $date_string ( string ) The date string can be in one of the following formats: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format refer to RFC2616 for the details (GMT is assumed, regardless of the used timezone). ret: $date_parsed ( number ) the number of microseconds since 1 Jan 1970 GMT, or 0 if out of range or if the date is invalid. since: 2.0.00 Remember to divide the return value by 1_000_000 if you need it in seconds. "parse_rfc" Parse a string resembling an RFC 822 date. It's meant to be lenient in its parsing of dates. Hence, this will parse a wider range of dates than "parse_http()". $date_parsed = parse_rfc($date_string); arg1: $date_string ( string ) The date string can be in one of the following formats: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format Sun, 6 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sun, 06 Nov 94 08:49:37 GMT ; RFC 822 Sun, 6 Nov 94 08:49:37 GMT ; RFC 822 Sun, 06 Nov 94 08:49 GMT ; Unknown [drtr@ast.cam.ac.uk] Sun, 6 Nov 94 08:49 GMT ; Unknown [drtr@ast.cam.ac.uk] Sun, 06 Nov 94 8:49:37 GMT ; Unknown [Elm 70.85] Sun, 6 Nov 94 8:49:37 GMT ; Unknown [Elm 70.85] ret: $date_parsed ( number ) the number of microseconds since 1 Jan 1970 GMT, or 0 if out of range or if the date is invalid. since: 2.0.00 Remember to divide the return value by 1_000_000 if you need it in seconds. See Also mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.14.2 2011-02-08 libapache2-mod-perl2-2.0.7::docs::api::APR::Date(3pm)