Hi, How to get the current date value in epoch i.e., number of days elapsed since 1970-1-1. I need solution in unix shell script.
A:
Depending on the language you're using it's going to be something simple like
CInt(CDate("1970-1-1") - CDate(Today()))
Ironically enough, yesterday was day 40,000 if you use 1/1/1900 as "day zero" like many computer systems use.
mandroid
2009-07-07 19:27:46
That looks like VB to me. The question asks in relation to a Unix shell script.
Noldorin
2009-07-07 19:32:43
He edited it after I answered. Thanks for your input anyway.
mandroid
2009-07-07 20:01:24
+1
A:
You mention you want a UNIX shell script. Peter J. Acklam wrote some shell scripts that may help you. Look here:
$ ./gymd2uday.sh
14432
$ echo $(( $(./gymd2uday.sh 1985 02 20) - $(./gymd2uday.sh 1970 1 1) ))
5529
As you can see, the default date is the current date. Peter's script does not use the %s
format specifier, so it may work for you.
Stephan202
2009-07-07 19:35:48
A:
The Unix Date command will display in epoch time
the command is
date +"%s"
http://unixhelp.ed.ac.uk/CGI/man-cgi?date
Edit: Some people have observed you asked for days, so it's the result of that command divided by 86,400
UberAlex
2009-07-07 19:36:12