<?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 Re: How to validate a parameter as a date in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471134#M775558</link>
    <description>Hi!&lt;BR /&gt;    I think writting a little C program serving the purpose would be an efficient one than touch or at, and it's not too hard.&lt;BR /&gt;    Right?&lt;BR /&gt;Regargs.&lt;BR /&gt;&lt;BR /&gt;Thinphony!</description>
    <pubDate>Thu, 07 Dec 2000 08:07:10 GMT</pubDate>
    <dc:creator>thinphony</dc:creator>
    <dc:date>2000-12-07T08:07:10Z</dc:date>
    <item>
      <title>How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471128#M775552</link>
      <description>I currently create a .sh script which will receive a date parameter (20001206). &lt;BR /&gt;&lt;BR /&gt;How can I validate the parameter is a valid date. Is there a shell function to compare the input string with a date format.&lt;BR /&gt;&lt;BR /&gt;Or, if there is none, how can I validate if the parameter is a valid number. Just do a test like "if [ $1 -lt 10000000 -o $1 -gt 99999999 ] gave me an error if the parameter contain alphanumerics (2000DEC06).&lt;BR /&gt;&lt;BR /&gt;Thanks for your help.</description>
      <pubDate>Wed, 06 Dec 2000 17:16:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471128#M775552</guid>
      <dc:creator>Admin.SIF</dc:creator>
      <dc:date>2000-12-06T17:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471129#M775553</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Given the format of your 'date' parameter, take it and concatenate "0000" to the end of it; 'touch' a file using the resultant string as a timestamp; and examine the return status.  If the exit status of the 'touch' is zero, then the 'date' was valid.  Thusly:&lt;BR /&gt;&lt;BR /&gt;# ARG=${ARG}0000&lt;BR /&gt;# touch -c -m -t $ARG /tmp/$$&lt;BR /&gt;# if [ "$?" = 0 ]&lt;BR /&gt;#   then&lt;BR /&gt;#   echo "date_OK"&lt;BR /&gt;# else&lt;BR /&gt;#   echo "invalid date: $ARG"&lt;BR /&gt;# fi&lt;BR /&gt;&lt;BR /&gt;Note that the '-c' argument to 'touch' prevents creating any file that you have to cleanup.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 06 Dec 2000 18:42:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471129#M775553</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-12-06T18:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471130#M775554</link>
      <description>It is a good one James !&lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;Madhu</description>
      <pubDate>Wed, 06 Dec 2000 18:53:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471130#M775554</guid>
      <dc:creator>Madhu Sudhan_1</dc:creator>
      <dc:date>2000-12-06T18:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471131#M775555</link>
      <description>Thanks! It works fine. One problem, it does not validate the day related with the month: If i enter "20000230", the date is accepted. But every one know there is no Feb. 30th.&lt;BR /&gt;Anyway, I'll take care of it. Thanks!</description>
      <pubDate>Wed, 06 Dec 2000 19:04:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471131#M775555</guid>
      <dc:creator>Admin.SIF</dc:creator>
      <dc:date>2000-12-06T19:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471132#M775556</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Ah, yes.  You are correct, the 'touch' only verifies that the day of the month is between 1-and-31 inclusive.  Hence a "month/day" of "0431" [also erroneous] would pass without further analysis.  My method is clearly a "first approximation" of correctness.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 06 Dec 2000 19:27:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471132#M775556</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-12-06T19:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471133#M775557</link>
      <description>It occurred to me that you might be able to use 'at' to check the date, based on James' original suggestion of appending '0000' to the variable.  But it seems that 'at' performs the same checks as 'touch'.  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;From an L1000 running 11.00...&lt;BR /&gt;&lt;BR /&gt;sandbox:/&amp;gt;echo ":" | at -t 200104310000&lt;BR /&gt;warning: commands will be executed using /usr/bin/sh&lt;BR /&gt;job 988639200.a at Tue May  1 00:00:00 2001&lt;BR /&gt;sandbox:/&amp;gt;&lt;BR /&gt;&lt;BR /&gt;That looks like a bug to me.  What do you people think?&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Dec 2000 00:46:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471133#M775557</guid>
      <dc:creator>Matt Livingston</dc:creator>
      <dc:date>2000-12-07T00:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471134#M775558</link>
      <description>Hi!&lt;BR /&gt;    I think writting a little C program serving the purpose would be an efficient one than touch or at, and it's not too hard.&lt;BR /&gt;    Right?&lt;BR /&gt;Regargs.&lt;BR /&gt;&lt;BR /&gt;Thinphony!</description>
      <pubDate>Thu, 07 Dec 2000 08:07:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471134#M775558</guid>
      <dc:creator>thinphony</dc:creator>
      <dc:date>2000-12-07T08:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471135#M775559</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Here is a small C program, based on the getdate function.&lt;BR /&gt;Check 'man getdate' for further personalized input formats.&lt;BR /&gt;&lt;BR /&gt;--- cut here&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;&lt;BR /&gt;main(argc,argv)&lt;BR /&gt;int argc;&lt;BR /&gt;char **argv;&lt;BR /&gt;{&lt;BR /&gt;struct tm *checked_date;&lt;BR /&gt;&lt;BR /&gt;if(argc != 2) {&lt;BR /&gt;        fprintf(stderr,"Usage: $0 date_string\n");&lt;BR /&gt;        exit(1);&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;if((checked_date=getdate(*++argv))==NULL){&lt;BR /&gt;        fprintf(stderr, "Wrong date format: %s\n", *argv);&lt;BR /&gt;        fprintf(stderr, "getdate_err = %d\n", getdate_err);&lt;BR /&gt;        exit(1);&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;                fprintf(stderr, "Like this date: %s\n", *argv);&lt;BR /&gt;}&lt;BR /&gt;--- cut here&lt;BR /&gt;&lt;BR /&gt;Personalised format should be in a file pointed to the environment variable DATEMSK which, in your case, should contain the following 2 lines:&lt;BR /&gt;&lt;BR /&gt;--- cut here&lt;BR /&gt;%Y%b%d&lt;BR /&gt;%Y%m%d&lt;BR /&gt;--- cut here&lt;BR /&gt;&lt;BR /&gt;Formats accepted are for example:&lt;BR /&gt;2000DEC09&lt;BR /&gt;20001209&lt;BR /&gt;&lt;BR /&gt;As getdate() checks for date validity, all input like april 31st or february 29 2001 will be rejected.&lt;BR /&gt;&lt;BR /&gt;Modify the file pointed to by DATEMSK according to your needs if you want more input formats.&lt;BR /&gt;The c program is writing error to stderr, it should be quite straightforward to modify as well.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;PS: This is a 'quick and dirty' check only, as I'm just verifying if getdate() is returning NULL or not.  ;-)&lt;BR /&gt;&lt;BR /&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Thu, 07 Dec 2000 11:04:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471135#M775559</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2000-12-07T11:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471136#M775560</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;More dirty than quick.... I forgot the exit(0) in case all went well.&lt;BR /&gt;&lt;BR /&gt;Here is the modified source:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;&lt;BR /&gt;main(argc,argv)&lt;BR /&gt;int argc;&lt;BR /&gt;char **argv;&lt;BR /&gt;{&lt;BR /&gt;struct tm *checked_date;&lt;BR /&gt;&lt;BR /&gt;if(argc != 2) {&lt;BR /&gt;        fprintf(stderr,"Usage: $0 date_string\n");&lt;BR /&gt;        exit(1);&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;if((checked_date=getdate(*++argv))==NULL){&lt;BR /&gt;        fprintf(stderr, "Wrong date format: %s\n", *argv);&lt;BR /&gt;        fprintf(stderr, "getdate_err = %d\n", getdate_err);&lt;BR /&gt;        exit(1);&lt;BR /&gt;        }&lt;BR /&gt;        else  {&lt;BR /&gt;                fprintf(stderr, "Like this date: %s\n", *argv);&lt;BR /&gt;                exit(0);&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Thu, 07 Dec 2000 11:07:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471136#M775560</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2000-12-07T11:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate a parameter as a date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471137#M775561</link>
      <description>Thanks for the C program. I apply some minor changes due to the C Compiler we use.&lt;BR /&gt;&lt;BR /&gt;--- Cut here ---&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;  struct tm *checked_date;&lt;BR /&gt;  if(argc != 2)&lt;BR /&gt;    {&lt;BR /&gt;      fprintf(stderr,"\tUsage: check_date [date]\n\n");&lt;BR /&gt;      return (1);&lt;BR /&gt;    }&lt;BR /&gt;  if((checked_date=getdate(*++argv))==NULL)&lt;BR /&gt;    {&lt;BR /&gt;      /* error: Invalid date or format */&lt;BR /&gt;      return (1);&lt;BR /&gt;    }&lt;BR /&gt;  return (0);&lt;BR /&gt;}&lt;BR /&gt;--- End cut ---&lt;BR /&gt;&lt;BR /&gt;Also, I remove unwanted fprintf to be able to use it into a sh script as a boolean result:&lt;BR /&gt;&lt;BR /&gt;--- Cut Here ---&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;if [ ${#} = 1 ] ; then&lt;BR /&gt;  if check_date ${1}&lt;BR /&gt;  then&lt;BR /&gt;    echo "Continue process"&lt;BR /&gt;  else&lt;BR /&gt;    echo "Invalide date. Stop process."&lt;BR /&gt;    exit&lt;BR /&gt;  fi&lt;BR /&gt;fi&lt;BR /&gt;--- End Cut ---&lt;/TIME.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 08 Dec 2000 17:35:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-validate-a-parameter-as-a-date/m-p/2471137#M775561</guid>
      <dc:creator>Admin.SIF</dc:creator>
      <dc:date>2000-12-08T17:35:46Z</dc:date>
    </item>
  </channel>
</rss>

