Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!ai-lab!mole.gnu.ai.mit.edu!ble From: ble@mole.gnu.ai.mit.edu (Bob Lee) Newsgroups: comp.unix.questions Subject: Re: date to unix seconds Keywords: date time seconds Message-ID: <14353@life.ai.mit.edu> Date: 25 Mar 91 16:10:34 GMT References: <1991Mar23.170730.18188@cbnews.att.com> Sender: news@ai.mit.edu Distribution: usa Lines: 20 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); }