delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/14/20:00:24

From: "Rafael García" <rafael AT geninfor DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: mktime(01/01/70;00:00:XX)
Date: Wed, 14 Mar 2001 21:14:09 +0100
Organization: BT Tel. Netnews service (readers)
Lines: 33
Message-ID: <3aafd182@filemon.telecable.es>
NNTP-Posting-Host: filemon.telecable.es
Mime-Version: 1.0
X-Trace: titan.bt.es 984600864 16466 212.89.0.4 (14 Mar 2001 20:14:24 GMT)
X-Complaints-To: abuse AT bt DOT es
NNTP-Posting-Date: 14 Mar 2001 20:14:24 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Original-NNTP-Posting-Host: cm05118.telecable.es
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Did you use mktime to get an scalar value to compare dates/times?

I have something like this:

long nseconds(int year,int month,int day,int hour,int minute,int second) {
   static struct tm tm;

   tm.tm_year=year-1900;
   tm.tm_mon=month-1;
   tm.tm_mday=day;
   tm.tm_hour=hour;
   tm.tm_min=minute;
   tm.tm_sec=second;
   tm.tm_isdst=-1;
   return (long)mktime(&tm);
   }

Then I can do things like

if (nseconds(y2,m2,d2,h2,mi2,s2)-nseconds(y1,m1,d1,h1,mi1,s1)>=3600) ....

It seems to work, but when I give it low values of 1970, it returns -1, so I
am afraid it is bad technique.

Do I have to set all members of tm (wday,yday,gmtoff,zone)?
Do you know another system?
How do you do it?
You can use difftime but I'd like something more general, for example, to
store events in a database using a single number for timings.

Thank you very much


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019