date to unix seconds

Bob Lee ble at mole.gnu.ai.mit.edu
Tue Mar 26 02:10:34 AEST 1991


In <1991Mar23.170730.18188 at 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); }



More information about the Comp.unix.questions mailing list