<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic mktime() in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860676#M713745</link>
    <description>&lt;BR /&gt;With very limited C skills, I have put together the following prog that takes the date as input and outputs the date in UNIX timestamp format.&lt;BR /&gt;&lt;BR /&gt;I need this to test some password aging scripts we have.&lt;BR /&gt;&lt;BR /&gt;But I cannot seem to get this working and mktime() always returns -1.&lt;BR /&gt;&lt;BR /&gt;=============================================&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; char *DAYS[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};&lt;BR /&gt; char *MONTHS[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};&lt;BR /&gt; int DATE,YEAR,HR,MIN,SEC,i,DAY,MTH,TIMEST;&lt;BR /&gt; char WDAY[10],MONTH[10];&lt;BR /&gt;&lt;BR /&gt; strcpy(WDAY,argv[1]);&lt;BR /&gt; strcpy(MONTH,argv[2]);&lt;BR /&gt; DATE=atoi(argv[3]);&lt;BR /&gt; HR=atoi(argv[4]);&lt;BR /&gt; MIN=atoi(argv[5]);&lt;BR /&gt; SEC=atoi(argv[6]);&lt;BR /&gt; YEAR=atoi(argv[7]);&lt;BR /&gt;&lt;BR /&gt; printf("Input to the Program: %s %s %d %d:%d:%d %d\n",WDAY,MONTH,DATE,HR,MIN,SEC,YEAR);&lt;BR /&gt;  &lt;BR /&gt; for(i=0;strcmp(DAYS[i],NULL)!= 0;i++)&lt;BR /&gt;  {&lt;BR /&gt;     if (strcmp(DAYS[i],WDAY) == 0)&lt;BR /&gt;       DAY=i;&lt;BR /&gt;  } &lt;BR /&gt;  &lt;BR /&gt;  for(i=0;strcmp(MONTHS[i],NULL)!=0;i++)&lt;BR /&gt; {&lt;BR /&gt;     if(strcmp(MONTHS[i],MONTH) == 0)&lt;BR /&gt;        MTH=i+1;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; YEAR=YEAR-1900;&lt;BR /&gt;  &lt;BR /&gt; printf("%d %d %d %d %d %d %d\n",SEC,MIN,HR,DATE,MTH,YEAR,DAY);&lt;BR /&gt;&lt;BR /&gt; TIMEST=mktime(SEC,MIN,HR,DATE,MTH,YEAR,DAY,0,1);&lt;BR /&gt; &lt;BR /&gt; printf("TIMESTAMP : %d\n",TIMEST);&lt;BR /&gt;&lt;BR /&gt;} &lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;# cc some.c&lt;BR /&gt;# ./a.out Mon Sep 13 10 37 08 2004&lt;BR /&gt;Input to the Program: Mon Sep 13 10:37:8 2004&lt;BR /&gt;8 37 10 13 9 104 1&lt;BR /&gt;TIMESTAMP : -1&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;what am I missing here ?&lt;BR /&gt;&lt;BR /&gt;- Sundar&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
    <pubDate>Mon, 13 Sep 2004 17:12:39 GMT</pubDate>
    <dc:creator>Sundar_7</dc:creator>
    <dc:date>2004-09-13T17:12:39Z</dc:date>
    <item>
      <title>mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860676#M713745</link>
      <description>&lt;BR /&gt;With very limited C skills, I have put together the following prog that takes the date as input and outputs the date in UNIX timestamp format.&lt;BR /&gt;&lt;BR /&gt;I need this to test some password aging scripts we have.&lt;BR /&gt;&lt;BR /&gt;But I cannot seem to get this working and mktime() always returns -1.&lt;BR /&gt;&lt;BR /&gt;=============================================&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; char *DAYS[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};&lt;BR /&gt; char *MONTHS[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};&lt;BR /&gt; int DATE,YEAR,HR,MIN,SEC,i,DAY,MTH,TIMEST;&lt;BR /&gt; char WDAY[10],MONTH[10];&lt;BR /&gt;&lt;BR /&gt; strcpy(WDAY,argv[1]);&lt;BR /&gt; strcpy(MONTH,argv[2]);&lt;BR /&gt; DATE=atoi(argv[3]);&lt;BR /&gt; HR=atoi(argv[4]);&lt;BR /&gt; MIN=atoi(argv[5]);&lt;BR /&gt; SEC=atoi(argv[6]);&lt;BR /&gt; YEAR=atoi(argv[7]);&lt;BR /&gt;&lt;BR /&gt; printf("Input to the Program: %s %s %d %d:%d:%d %d\n",WDAY,MONTH,DATE,HR,MIN,SEC,YEAR);&lt;BR /&gt;  &lt;BR /&gt; for(i=0;strcmp(DAYS[i],NULL)!= 0;i++)&lt;BR /&gt;  {&lt;BR /&gt;     if (strcmp(DAYS[i],WDAY) == 0)&lt;BR /&gt;       DAY=i;&lt;BR /&gt;  } &lt;BR /&gt;  &lt;BR /&gt;  for(i=0;strcmp(MONTHS[i],NULL)!=0;i++)&lt;BR /&gt; {&lt;BR /&gt;     if(strcmp(MONTHS[i],MONTH) == 0)&lt;BR /&gt;        MTH=i+1;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; YEAR=YEAR-1900;&lt;BR /&gt;  &lt;BR /&gt; printf("%d %d %d %d %d %d %d\n",SEC,MIN,HR,DATE,MTH,YEAR,DAY);&lt;BR /&gt;&lt;BR /&gt; TIMEST=mktime(SEC,MIN,HR,DATE,MTH,YEAR,DAY,0,1);&lt;BR /&gt; &lt;BR /&gt; printf("TIMESTAMP : %d\n",TIMEST);&lt;BR /&gt;&lt;BR /&gt;} &lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;# cc some.c&lt;BR /&gt;# ./a.out Mon Sep 13 10 37 08 2004&lt;BR /&gt;Input to the Program: Mon Sep 13 10:37:8 2004&lt;BR /&gt;8 37 10 13 9 104 1&lt;BR /&gt;TIMESTAMP : -1&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;what am I missing here ?&lt;BR /&gt;&lt;BR /&gt;- Sundar&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 13 Sep 2004 17:12:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860676#M713745</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-13T17:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860677#M713747</link>
      <description>&amp;gt;&amp;gt;&amp;gt; what am I missing here ?&lt;BR /&gt;&lt;BR /&gt;You should have opted for perl!&lt;BR /&gt;&lt;BR /&gt;Seriously,&lt;BR /&gt;Check out 'man mktime'&lt;BR /&gt;&lt;BR /&gt;You'll see the call takes only 1 argument, an array (ok, struct) containing those 9 arguments you passed.&lt;BR /&gt;You'll also see it tells you to '#include &lt;TIME.H&gt;"&lt;BR /&gt;Do that. It declares 'struct tm' for you.&lt;BR /&gt;&lt;BR /&gt;I'm sure you can take it from there....&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/TIME.H&gt;</description>
      <pubDate>Mon, 13 Sep 2004 18:01:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860677#M713747</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-09-13T18:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860678#M713749</link>
      <description>Your fundamental problem is that mktime() expects a pointer to struct tm as an argument not a bunch of integers. You need to build up a struct tm and then send this in:&lt;BR /&gt;&lt;BR /&gt;First declare a struct tm then populate it.&lt;BR /&gt;&lt;BR /&gt;struct tm t;&lt;BR /&gt;time_t seconds = 0;&lt;BR /&gt;&lt;BR /&gt;t.tm_sec = SEC % 61;&lt;BR /&gt;t.tm_min = MIN % 60;&lt;BR /&gt;t.tm_hour = HR % 24;&lt;BR /&gt;t.tm_mday = DATE % 32;&lt;BR /&gt;t.tm_mon = MTH - 1 /* 0 - 11 */&lt;BR /&gt;t.tm_year = YEAR; /* year - 1900 */&lt;BR /&gt;t.tm_wday = t.tm_yday = 0; /* ignored */&lt;BR /&gt;t.tm_isdst = -1; /* This will may the system decide */&lt;BR /&gt;&lt;BR /&gt;seconds = mktime(&amp;amp;t);&lt;BR /&gt;(void) printf("%ld\n",seconds);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Sep 2004 18:04:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860678#M713749</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-09-13T18:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860679#M713750</link>
      <description>oh... forgot to add. Check out recent topic:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=681997" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=681997&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It has some perl and shell code examples in this very area. (One of my replies there figures out time in seconds, just does nto print it).&lt;BR /&gt;&lt;BR /&gt;Hein.</description>
      <pubDate>Mon, 13 Sep 2004 18:12:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860679#M713750</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-09-13T18:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860680#M713751</link>
      <description>Thanks for responding.&lt;BR /&gt;&lt;BR /&gt;Yes, I understand mktime() accepts only the structure as the argument.&lt;BR /&gt;&lt;BR /&gt;But I "based" my C prog on a perl excerpt that is listed on the URL&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20090888.html" target="_blank"&gt;http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20090888.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I didnt want to just copy and use the perl code since I dont understand PERL and wanted to write something similar in C, which I understand a little bit.&lt;BR /&gt;&lt;BR /&gt;the perl code in the site seem to call mktime with bunch of integers( $timestamp = mktime($sec, $min, $hour, $date, $month, $year, $wday, 0, -1);) and it is working.  Wondering why a similar call to mktime() from a C program returns -1 ?.</description>
      <pubDate>Mon, 13 Sep 2004 18:18:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860680#M713751</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-13T18:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860681#M713752</link>
      <description>hmm..I got this working, atlast :-)&lt;BR /&gt;&lt;BR /&gt;============================================#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;struct t_ptr&lt;BR /&gt;{&lt;BR /&gt;  int SEC;&lt;BR /&gt;  int MIN;&lt;BR /&gt;  int HR;&lt;BR /&gt;  int DATE;&lt;BR /&gt;  int MTH;&lt;BR /&gt;  int YEAR;&lt;BR /&gt;  int DAY;&lt;BR /&gt;  int YDAY;&lt;BR /&gt;  int ISDST;&lt;BR /&gt;}; &lt;BR /&gt; &lt;BR /&gt;main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; char *DAYS[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};&lt;BR /&gt; char *MONTHS[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};&lt;BR /&gt; struct t_ptr t1;&lt;BR /&gt; int i,TIMEST;&lt;BR /&gt; char WDAY[10],MONTH[10];&lt;BR /&gt;&lt;BR /&gt; strcpy(WDAY,argv[1]);&lt;BR /&gt; strcpy(MONTH,argv[2]);&lt;BR /&gt; t1.DATE=atoi(argv[3]);&lt;BR /&gt; t1.HR=atoi(argv[4]);&lt;BR /&gt; t1.MIN=atoi(argv[5]);&lt;BR /&gt; t1.SEC=atoi(argv[6]);&lt;BR /&gt; t1.YEAR=atoi(argv[7]);&lt;BR /&gt; t1.YDAY=0;&lt;BR /&gt; t1.ISDST=-1;&lt;BR /&gt; &lt;BR /&gt; printf("Input to the Program: %s %s %d %d:%d:%d %d\n",WDAY,MONTH,t1.DATE,t1.HR,t1.MIN,t1.SEC,t1.YEAR);&lt;BR /&gt;  &lt;BR /&gt; for(i=0;strcmp(DAYS[i],NULL)!= 0;i++)&lt;BR /&gt;  {&lt;BR /&gt;     if (strcmp(DAYS[i],WDAY) == 0)&lt;BR /&gt;       t1.DAY=i;&lt;BR /&gt;  } &lt;BR /&gt;  &lt;BR /&gt;  for(i=0;strcmp(MONTHS[i],NULL)!=0;i++)&lt;BR /&gt; {&lt;BR /&gt;     if(strcmp(MONTHS[i],MONTH) == 0)&lt;BR /&gt;        t1.MTH=i;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; t1.YEAR-=1900;&lt;BR /&gt;  &lt;BR /&gt; printf("%d %d %d %d %d %d %d\n",t1.SEC,t1.MIN,t1.HR,t1.DATE,t1.MTH,t1.YEAR,t1.DAY);&lt;BR /&gt;&lt;BR /&gt; TIMEST=mktime(t1);&lt;BR /&gt; &lt;BR /&gt; printf("TIMESTAMP : %d\n",TIMEST);&lt;BR /&gt;&lt;BR /&gt;} &lt;BR /&gt;============================================&lt;BR /&gt;&lt;BR /&gt;But still not clear why call to mktime() with bunch of integers always return -1 where as a similar call in perl works ?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 13 Sep 2004 18:55:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860681#M713752</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-13T18:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860682#M713753</link>
      <description>Perl does NOT offer the system naked services.&lt;BR /&gt;There is no one-on-one mapping.&lt;BR /&gt;It just offers look-a-like, sound-a-like, do-a-like function with a perl flavor to it.&lt;BR /&gt;&lt;BR /&gt;Building structure is trivial in C, hard in PERL. So Perl provides a structure-less interface.&lt;BR /&gt;&lt;BR /&gt;fwiw, I consider your program broken. You have not passed a tm struct as you are supposed to, just something that happend to look an awfull lot like a struct tm. That's confusing, poor practice, error prone and requires additional work. The errors will happen when 'int' suddenly changes to 64 bit or 16 bit. When a port is done. When you moved on. 'they' will keep time.h honest. Noone will take are of you struct t_ptr or will know (at first glance) what it might stand for.&lt;BR /&gt;&lt;BR /&gt;Just do that include time.h and use struct tm.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; But still not clear why call to mktime() with bunch of integers always return -1 where as a similar call in perl works ? &lt;BR /&gt;&lt;BR /&gt;That's the perl value-add. It tries to make life easy for most, at the price of confusing some.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Sep 2004 22:45:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860682#M713753</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-09-13T22:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860683#M713754</link>
      <description>Thanks Hein. I understand it is a poor practice to define my own structure instead of using existing one.&lt;BR /&gt;&lt;BR /&gt;I am not a seasoned programmer neither there going to be a quality audit :-). Bottom line is, the above code gets the work done for me.&lt;BR /&gt;&lt;BR /&gt;But yours and Clay's posts are educational, as always.&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Sep 2004 10:59:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860683#M713754</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-14T10:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: mktime()</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860684#M713755</link>
      <description>See above.</description>
      <pubDate>Tue, 14 Sep 2004 13:02:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/mktime/m-p/4860684#M713755</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-14T13:02:10Z</dc:date>
    </item>
  </channel>
</rss>

