[comp.unix.questions] date to unix seconds

reo@cbnews.att.com (robert.e.o'brien) (03/24/91)

I get data from a database that I want to do some statistical
analysis on.  Part of the data is a date in typical  mm/dd/yy
format.  I want to convert this to a number.  Unix seconds is fine
since this data doesn't go back further than 1989.  I looked at the
Unix "date" command and it talked about superusers using the date
command to set the time on the machine in Unix seconds.  Also about
getting the current back out in a variety of formats.  I couldn't 
find the program where you put in a data and get out seconds.
Give that I get the program that goes from date to seconds, I'd
also like a program that goes the other way.  Thanks.

Bob O'Brien

jik@athena.mit.edu (Jonathan I. Kamens) (03/25/91)

  See Message <91Mar23.034527edt.1008@smoke.cs.toronto.edu>, posted in the
last couple of days to alt.sources.wanted and comp.sources.wanted.  It
explains how to get the date code from the C news sources; that code will do
what you want.

  Well, sort of.  It doesn't parse fully numeric dates (i.e. the mm/dd/yy
format you mentioned) in order to avoid ambiguity between US/European number
order.  However, you can get around this problem by changing the date string
slightly (e.g. by changing the mm number to the alphabetic abbreviation for
the month) before passing it into the C news code.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

ble@mole.gnu.ai.mit.edu (Bob Lee) (03/26/91)

In <1991Mar23.170730.18188@cbnews.att.com>, Bob O'Brien writes:

> I get data from a database that I want to do some statistical
> analysis on.  Part of the data is a date in typical  mm/dd/yy
> format.  I want to convert this to a number.  Unix seconds is fine
> since this data doesn't go back further than 1989.  I looked at the
> Unix "date" command and it talked about superusers using the date
> command to set the time on the machine in Unix seconds.  Also about
> getting the current back out in a variety of formats.  I couldn't 
> find the program where you put in a data and get out seconds.
> Give that I get the program that goes from date to seconds, I'd
> also like a program that goes the other way.  Thanks.


   /* returns  the number of days from 01/01/1970 to month, day, year */

ndays(month, day, year) int month, day, year; { int f;
    f = (365 * year - 719528) + day + 31 * (month - 1);
    if(month < 3) return(f + (year - 1)/4 - (3 * (1 + (year - 1)/100))/4);
    else return(f + year/4 - (3 * (1 + year/100))/4 - (4 * month + 23)/10); }