Calculate difference in dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank

    Calculate difference in dates

    For my website i would like to display the age of my son in years,
    months, days and hours.

    For now i manage to get a result for totals. Like the total number of
    days.

    This is the beginning:

    starttime = Date.parse("Aug 10,2003, 07:07")
    sdt = new Date(starttime)
    starttime= Math.ceil((star ttime) / 1000 / 60 / 60 / 24 )
    ndt = new Date()

    y = sdt.getYear()
    m = sdt.getMonth() + 1
    d = sdt.getDate()
    h = starttime

    Thanx
  • Evertjan.

    #2
    Re: Calculate difference in dates

    Frank wrote on 29 aug 2004 in comp.lang.javas cript:
    [color=blue]
    > For my website i would like to display the age of my son in years,
    > months, days and hours.
    >
    > For now i manage to get a result for totals. Like the total number of
    > days.
    >
    > This is the beginning:
    >
    > starttime = Date.parse("Aug 10,2003, 07:07")
    > sdt = new Date(starttime)
    > starttime= Math.ceil((star ttime) / 1000 / 60 / 60 / 24 )
    > ndt = new Date()
    >
    > y = sdt.getYear()
    > m = sdt.getMonth() + 1
    > d = sdt.getDate()
    > h = starttime[/color]

    A bit young for your son toread the web ;-}

    Read the faq:

    <http://www.merlyn.demo n.co.uk/js-date0.htm#DC>
    and
    <http://www.merlyn.demo n.co.uk/js-date1.htm#diff>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Michael Winter

      #3
      Re: Calculate difference in dates

      On 29 Aug 2004 08:18:46 -0700, Frank <fak1234@hotmai l.com> wrote:
      [color=blue]
      > For my website i would like to display the age of my son in years,
      > months, days and hours.
      >
      > For now i manage to get a result for totals. Like the total number of
      > days.
      >
      > This is the beginning:
      >
      > starttime = Date.parse("Aug 10,2003, 07:07")[/color]

      It would be safer to use numbers, rather than a string as there is no
      exact definition for string date formats. I'm certain that the format
      above will cause problems in some browsers.

      var birth = new Date(2003, 7, 10, 7, 7);

      [snip]

      Calculating differences in dates is simply a matter of subtracting one
      Date object from another. This will yield a number representing the
      milliseconds. You can then use a new Date object to return the number of
      years, months, days and hours:

      var difference = new Date(new Date() - birth),
      years = difference.getF ullYear() - 1970,
      months = difference.getM onth(),
      days = difference.getD ate() - 1,
      hours = difference.getH ours(),
      t = new String(years);

      The adjustments above are based on the fact that a time of zero (0)
      represents the date, 01-Jan-1970 00:00:00 GMT. The adjustments make the
      respective values zero-based.

      t += ' year';
      if(1 != years) {t += 's';}
      t += ', ' + months + ' month';
      if(1 == months) {t += 's';}
      t += ', ' + days + ' day';
      if(1 == days) {t += 's';}
      t += ', and ' + hours + ' hour';
      if(1 == hours) {t += 's';}
      alert(t);

      Hope that helps,
      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Dr John Stockton

        #4
        Re: Calculate difference in dates

        JRS: In article <opsdh37io1x13k vk@atlantis>, dated Sun, 29 Aug 2004
        16:01:43, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
        ueyonder.co.inv alid> posted :[color=blue]
        >On 29 Aug 2004 08:18:46 -0700, Frank <fak1234@hotmai l.com> wrote:
        >[color=green]
        >> For my website i would like to display the age of my son in years,
        >> months, days and hours.
        >>
        >> For now i manage to get a result for totals. Like the total number of
        >> days.
        >>
        >> This is the beginning:
        >>
        >> starttime = Date.parse("Aug 10,2003, 07:07")[/color]
        >
        >It would be safer to use numbers, rather than a string as there is no
        >exact definition for string date formats. I'm certain that the format
        >above will cause problems in some browsers.[/color]

        Can anyone provide an actual example of failure? ISTM worth settling
        the point of whether all javascript systems, however configured, can
        read a date with English-MON DD YYYY in arbitrary order and
        reasonable punctuation.
        [color=blue]
        > var birth = new Date(2003, 7, 10, 7, 7);[/color]

        Not fully equivalent, though; the first returns a time_t (ms) and the
        second a Date Object.

        That form uses Month-1, and hence is amenable to human error; I'd
        suggest new Date("2003/08/10 07:07") , in which the string looks like
        the right date and is as near ISO-8601 as my system accepts. Again, can
        anyone find an example of failure of that form?

        [color=blue]
        >[snip]
        >
        >Calculating differences in dates is simply a matter of subtracting one
        >Date object from another.[/color]

        No. It does give the absolute time interval.
        [color=blue]
        > This will yield a number representing the
        >milliseconds .[/color]

        Yes.
        [color=blue]
        > You can then use a new Date object to return the number of
        >years, months, days and hours:[/color]

        No; *a* number of ...

        Consider a boy born 2004-01-01 00:00:00; at 2008-12-31 12:00:00 he will
        be nearly 5 years old, and looking forward to his party on the next day.
        He will be 1461 + 365.5 days old.

        Consider a boy born 1970-01-01 00:00:00; he will be 1461 + 365.5 days
        old on 1975-01-01 12:00:00 he will be 5 years old, and looking forward
        to his party on that afternoon.


        A boy born 2004-02-01 will be a month old on 2004-03-01 ; 29 days.
        A boy born 2005-02-01 will be a month old on 2005-03-01 ; 28 days.
        Starting from 1970-01-01, 29/28 days is not yet a month.

        The lad was 6 months old on 2004-02-10;

        starttime = Date.parse("Aug 10,2003, 07:07")
        finaltime = Date.parse("Feb 10,2004, 07:07")

        D = new Date(finaltime-starttime)

        gives me Sat Jul 4 02:00:00 UTC+0100 1970 -> 6 mo 3 dy 2 hr; the
        same every year, since the end of Feb real time is not crossed.


        Now consider those, of all ages, who were born on March 28th at noon.
        They will have been a week old on the following April 4th, at noon. But
        in Europe[~] 3/7 of them will then have been an hour younger than the
        other 4/7; and probably /vice versa/ in much of the USA.

        [~] EU & neighbours; but not Iceland (there may be other exceptions).

        Moreover, the lad may be a foreigner. Differences from GMT will be
        (too) properly allowed for in determining the interval; but datum is
        1970.0 GMT. Your method, which adds diff to datum and then uses the
        getFullYear family, gives a result depending on the location of the
        answering system. Few places use GMT as civil time year-round.
        [color=blue]
        > t += ' year';
        > if(1 != years) {t += 's';}
        > t += ', ' + months + ' month';
        > if(1 == months) {t += 's';}
        > t += ', ' + days + ' day';
        > if(1 == days) {t += 's';}
        > t += ', and ' + hours + ' hour';
        > if(1 == hours) {t += 's';}
        > alert(t);[/color]

        Erroneous pluralisation?



        IMHO, the OP needs to step forwards in integer civil years from the DoB
        until the next step will pass the present instant, counting them; then
        likewise in months, days, hours, and minutes.

        He could step backwards; I expect that the answer will sometimes[*]
        differ.
        [*] Assuming that the OP repeats the test for a statistically-
        significant[+] number of sons[#].
        [+] Which need not be all his own.
        [#] Or daughters, wives, etc.


        A further correction, probably of about 9 months, will be needed if the
        lad is Korean (4.5 mo if half-Korean?), and the stated date is DoB.


        See via below.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • Michael Winter

          #5
          Re: Calculate difference in dates

          On Mon, 30 Aug 2004 17:19:23 +0100, Dr John Stockton
          <spam@merlyn.de mon.co.uk> wrote:
          [color=blue]
          > JRS: In article <opsdh37io1x13k vk@atlantis>, dated Sun, 29 Aug 2004
          > 16:01:43, seen in news:comp.lang. javascript, Michael Winter
          > <M.Winter@bluey onder.co.invali d> posted :
          >[color=green]
          >> On 29 Aug 2004 08:18:46 -0700, Frank <fak1234@hotmai l.com> wrote:[/color][/color]

          [snip]
          [color=blue][color=green][color=darkred]
          >>> starttime = Date.parse("Aug 10,2003, 07:07")[/color]
          >>
          >> It would be safer to use numbers, rather than a string as there is no
          >> exact definition for string date formats. I'm certain that the format
          >> above will cause problems in some browsers.[/color]
          >
          > Can anyone provide an actual example of failure? ISTM worth settling
          > the point of whether all javascript systems, however configured, can
          > read a date with English-MON DD YYYY in arbitrary order and
          > reasonable punctuation.[/color]

          Would it be possible? As there is no definition on what should result, or
          be accepted, in any of the string-related methods, it would be up to the
          developers to decide what should be a reasonable format. That said, I
          agree: it would be nice to know.
          [color=blue][color=green]
          >> var birth = new Date(2003, 7, 10, 7, 7);[/color]
          >
          > Not fully equivalent, though; the first returns a time_t (ms) and the
          > second a Date Object.[/color]

          Yes. Sorry about that.
          [color=blue]
          > That form uses Month-1, and hence is amenable to human error;[/color]

          True. I did mean to describe the arguments. However, once documented, it
          shouldn't be of any concern.

          So, for that description...

          var birth = new Date(
          2003, // Year
          7, // Month, starting from zero. 0-Jan 1-Feb 2-March ...
          10, // Date
          7, // Hours
          7); // Minutes

          [snip]
          [color=blue][color=green]
          >> Calculating differences in dates is simply a matter of subtracting one
          >> Date object from another.[/color]
          >
          > No. It does give the absolute time interval.[/color]

          Could you explain what you see as the difference? Is it a matter of
          semantics, or something more substantial?

          [snip]
          [color=blue][color=green]
          >> You can then use a new Date object to return the number of
          >> years, months, days and hours:[/color][/color]

          [snipped long example]

          Hmm. Yes, I see the problem.
          [color=blue][color=green]
          >> t += ' year';
          >> if(1 != years) {t += 's';}
          >> t += ', ' + months + ' month';
          >> if(1 == months) {t += 's';}
          >> t += ', ' + days + ' day';
          >> if(1 == days) {t += 's';}
          >> t += ', and ' + hours + ' hour';
          >> if(1 == hours) {t += 's';}
          >> alert(t);[/color]
          >
          > Erroneous pluralisation?[/color]

          Unfortunately. When I tested what I wrote, I corrected that sequence but I
          didn't copy the changes back to my post. The comparisons should all be
          "not equal".

          [snip]

          It never ceases to amaze me how something as seemingly simple as date
          manipulation can turn into such a minefield.

          Thank you,
          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Frank

            #6
            Re: Calculate difference in dates

            "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message news:<opsdh37io 1x13kvk@atlanti s>...[color=blue]
            > var birth = new Date(2003, 7, 10, 7, 7);
            > var difference = new Date(new Date() - birth),
            > years = difference.getF ullYear() - 1970,
            > months = difference.getM onth(),
            > days = difference.getD ate() - 1,
            > hours = difference.getH ours(),
            > t = new String(years);
            >
            > t += ' year';
            > if(1 != years) {t += 's';}
            > t += ', ' + months + ' month';
            > if(1 == months) {t += 's';}
            > t += ', ' + days + ' day';
            > if(1 == days) {t += 's';}
            > t += ', and ' + hours + ' hour';
            > if(1 == hours) {t += 's';}
            > alert(t);[/color]

            Hi Thanks you both for responding.

            Comment

            • Frank

              #7
              Re: Calculate difference in dates

              Hi i'm sorry but this is i think a bit over my head as a newbe.

              Do you guys have a complete answer for me, because i got lost.
              I really appriciate the input.

              Thanx in advance.

              Comment

              • Otter

                #8
                Re: Calculate difference in dates

                On 29 Aug 2004 08:18:46 -0700, fak1234@hotmail .com (Frank) wrote:
                [color=blue]
                >For my website i would like to display the age of my son in years,
                >months, days and hours.[/color]

                Frank - if you ever get/got this to work could you please post the
                code? I've been looking to do the exact same thing for a good two
                years now. Every once in a while I seach the net for code but the
                best I can find only gives total number of days, months, etc (ie: 30
                months, 919 days, etc). In fact this is the very reason I'm reading
                this group now!

                I don't know anything about javascript so I am completely lost.

                Eternally grateful,

                -Otter

                Comment

                • Ian Sedwell

                  #9
                  Re: Calculate difference in dates

                  Hi guys

                  This won't immediately solve your problems, but it will go a long way to
                  showing you what's involved. Anyway, it's more fun to do some of the work
                  yourselves :-)

                  /////////////////////////////////////////////////////////////////////////
                  // //
                  // These functions access the user's local date and time. //
                  // //
                  /////////////////////////////////////////////////////////////////////////

                  //
                  // This function returns the date.
                  //
                  function getDateNow () {
                  var dayNames = new
                  Array("Sunday", "Monday","Tuesd ay","Wednesday" ,"Thursday","Fr iday","Saturday "
                  );
                  var monthNames = new
                  Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se p
                  tember","Octobe r","November"," December");
                  var theDate = new Date;

                  return dayNames[theDate.getDay( )] + ", " + monthNames[theDate.getMont h()]
                  + ", " + theDate.getDate ();
                  }

                  //
                  // This function returns the time in 12-hour clock format.
                  //
                  function getTimeNow () {
                  var theDate = new Date;

                  return showZeroFill(sh owTheHour(theDa te.getHours())) + ":" +
                  showZeroFill(th eDate.getMinute s()) + ":" +
                  showZeroFill(th eDate.getSecond s()) + " " + showAMPM(theDat e);
                  }

                  //
                  // Mos people using this site are not likely to be familiar with the 24-hour
                  clock,
                  // or "military time". So this, used in conjunction with "showAMPM", makes
                  sure that
                  // times are described in the more familiar format.
                  //
                  function showTheHour (theHour) {
                  if ((theHour > 0) && (theHour < 13)) {
                  return theHour;
                  }
                  else {
                  if (theHour == 0) {
                  return theHour;
                  }
                  else {
                  return (theHour - 12);
                  }
                  }
                  }

                  //
                  // Pad the a time value with a 0 to the left, if it is less than 10.
                  //
                  function showZeroFill (theValue) {
                  if (theValue > 9) {
                  return theValue;
                  }
                  else {
                  return "0" + theValue;
                  }
                  }

                  //
                  // Return "AM" or "PM" according to the hour of the time.
                  //
                  function showAMPM (theDate) {
                  if (theDate.getHou rs() < 12) {
                  return "AM";
                  }
                  else {
                  return "PM";
                  }
                  }



                  On 2004/09/06 12:22, in article 14hoj05ti29hh4l b704sb6aek7t4dj lmvv@4ax.com,
                  "Otter" <Otter@nospam.n et> wrote:
                  [color=blue]
                  > On 29 Aug 2004 08:18:46 -0700, fak1234@hotmail .com (Frank) wrote:
                  >[color=green]
                  >> For my website i would like to display the age of my son in years,
                  >> months, days and hours.[/color]
                  >
                  > Frank - if you ever get/got this to work could you please post the
                  > code? I've been looking to do the exact same thing for a good two
                  > years now. Every once in a while I seach the net for code but the
                  > best I can find only gives total number of days, months, etc (ie: 30
                  > months, 919 days, etc). In fact this is the very reason I'm reading
                  > this group now!
                  >
                  > I don't know anything about javascript so I am completely lost.
                  >
                  > Eternally grateful,
                  >
                  > -Otter[/color]

                  Comment

                  • Kent Feiler

                    #10
                    Re: Calculate difference in dates

                    "Otter" <Otter@nospam.n et> wrote:
                    [color=blue]
                    > On 29 Aug 2004 08:18:46 -0700, fak1234@hotmail .com (Frank) wrote:
                    >[color=green]
                    >> For my website i would like to display the age of my son in years,
                    >> months, days and hours.[/color]
                    >
                    > Frank - if you ever get/got this to work could you please post the
                    > code? I've been looking to do the exact same thing for a good two
                    > years now. Every once in a while I seach the net for code but the
                    > best I can find only gives total number of days, months, etc (ie: 30
                    > months, 919 days, etc). In fact this is the very reason I'm reading
                    > this group now!
                    >
                    > I don't know anything about javascript so I am completely lost.
                    >
                    > Eternally grateful,
                    >
                    > -Otter[/color]
                    ------------------------------------------------------------------------------------------------------------------------

                    I have a section on my web page called "Clocks." Here's the URL:



                    It's not exactly what you want, but it's close. "Clocks" are
                    countdown clocks from the current date and time to some future
                    date/time. You might use one, for instance, to determine exactly how
                    long (in years, days, hours, minutes, and seconds) it is until you
                    retire, or until your birthday, or to the year 10,000, etc.

                    What you're after is a little different. You want the elapsed time
                    from some past event (your son's birthday) to the present. I suspect
                    that you could use most of the Javascript code in Clocks for what you
                    want, but you'd have to make changes. It's all downloadable. If you'd
                    like to look at it, check the HEEEELP section for download
                    instructions.


                    Regards,


                    Kent Feiler

                    Comment

                    • Dr John Stockton

                      #11
                      Re: Calculate difference in dates

                      JRS: In article <opsdj5hefsx13k vk@atlantis>, dated Mon, 30 Aug 2004
                      18:22:38, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
                      ueyonder.co.inv alid> posted :[color=blue]
                      >On Mon, 30 Aug 2004 17:19:23 +0100, Dr John Stockton
                      ><spam@merlyn.d emon.co.uk> wrote:
                      >[color=green]
                      >> JRS: In article <opsdh37io1x13k vk@atlantis>, dated Sun, 29 Aug 2004
                      >> 16:01:43, seen in news:comp.lang. javascript, Michael Winter
                      >> <M.Winter@bluey onder.co.invali d> posted :
                      >>[color=darkred]
                      >>> On 29 Aug 2004 08:18:46 -0700, Frank <fak1234@hotmai l.com> wrote:[/color][/color]
                      >
                      >[snip]
                      >[color=green][color=darkred]
                      >>>> starttime = Date.parse("Aug 10,2003, 07:07")
                      >>>
                      >>> It would be safer to use numbers, rather than a string as there is no
                      >>> exact definition for string date formats. I'm certain that the format
                      >>> above will cause problems in some browsers.[/color]
                      >>
                      >> Can anyone provide an actual example of failure? ISTM worth settling
                      >> the point of whether all javascript systems, however configured, can
                      >> read a date with English-MON DD YYYY in arbitrary order and
                      >> reasonable punctuation.[/color]
                      >
                      >Would it be possible? As there is no definition on what should result, or
                      >be accepted, in any of the string-related methods, it would be up to the
                      >developers to decide what should be a reasonable format. That said, I
                      >agree: it would be nice to know.[/color]


                      Certainly it would be possible. The three-letter abbreviation must be
                      the month; ignoring case, jan..dec, all else being an error. The four
                      digits must be the year, so the other field the day.

                      There is the question of what punctuation is reasonable; in mine, f,eb
                      gives NaN, but fe,b is OK (and GMT+2); an isolatable letter appears to
                      be taken as offset (j excluded).

                      My MSIE4 system accepts
                      Feb 3 2222 YES
                      Feb 3st 2222 NO
                      Feb 3nd 2222 NO
                      Feb 3rd 2222 NO
                      Feb 3th 2222 YES
                      where the last two are alarming.

                      --
                      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                      Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                      PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                      Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                      Comment

                      • Dr John Stockton

                        #12
                        Re: Calculate difference in dates

                        JRS: In article <14hoj05ti29hh4 lb704sb6aek7t4d jlmvv@4ax.com>, dated
                        Mon, 6 Sep 2004 06:22:12, seen in news:comp.lang. javascript, Otter
                        <Otter@nospam.n et> posted :[color=blue]
                        >On 29 Aug 2004 08:18:46 -0700, fak1234@hotmail .com (Frank) wrote:
                        >[color=green]
                        >>For my website i would like to display the age of my son in years,
                        >>months, days and hours.[/color]
                        >
                        >Frank - if you ever get/got this to work could you please post the
                        >code? I've been looking to do the exact same thing for a good two
                        >years now. Every once in a while I seach the net for code but the
                        >best I can find only gives total number of days, months, etc (ie: 30
                        >months, 919 days, etc). In fact this is the very reason I'm reading
                        >this group now![/color]

                        Evertjan wrote :-

                        Read the faq:

                        <http://www.merlyn.demo n.co.uk/js-date0.htm#DC>
                        and
                        <http://www.merlyn.demo n.co.uk/js-date1.htm#diff>

                        but perhaps he missed
                        <URL:http://www.merlyn.demo n.co.uk/js-dates.htm#Intro > !

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                        Comment

                        • Dr John Stockton

                          #13
                          Re: Calculate difference in dates

                          JRS: In article <BD624545.CDE5% ian.sedwell@btc lick.com>, dated Mon, 6
                          Sep 2004 15:46:19, seen in news:comp.lang. javascript, Ian Sedwell
                          <ian.sedwell@bt click.com> posted :
                          [color=blue]
                          >This won't immediately solve your problems, but it will go a long way to
                          >showing you what's involved. Anyway, it's more fun to do some of the work
                          >yourselves :-)[/color]

                          It seems rather a pointless contribution. Did you write it yourself?

                          Code posted in News should not be allowed to be line-wrapped by the
                          posting software; the poster should wrap it by hand himself. Or
                          herself.
                          [color=blue]
                          >// This function returns the time in 12-hour clock format.[/color]

                          A silly thing to do.

                          [color=blue]
                          >// Mos people using this site are not likely to be familiar with the 24-hour
                          >clock,[/color]

                          Most people here know it well; even the Americans.

                          [color=blue]
                          >function showTheHour (theHour) {
                          > if ((theHour > 0) && (theHour < 13)) {
                          > return theHour;
                          > }
                          > else {
                          > if (theHour == 0) {
                          > return theHour;
                          > }
                          > else {
                          > return (theHour - 12);
                          > }
                          > }
                          >}[/color]

                          ISTM that the above code does not do the customary thing for the first
                          hour of the day; but I've not run the code.

                          [color=blue]
                          >On 2004/09/06 12:22, in article 14hoj05ti29hh4l b704sb6aek7t4dj lmvv@4ax.com,
                          >"Otter" <Otter@nospam.n et> wrote:[/color]

                          Responses should go after trimmed quotes.

                          Carefully reading a newsgroup FAQ before posting to the group is
                          strongly recommended; anyone who posts an answer palpably inferior to
                          one indicated by the FAQ is liable to be considered, and described as,
                          injudicious.

                          --
                          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                          Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
                          Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                          Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

                          Comment

                          • Ian Sedwell

                            #14
                            Re: Calculate difference in dates

                            On 2004/09/06 20:56, in article YlNqFtChDMPBFwn 6@merlyn.demon. co.uk, "Dr
                            John Stockton" <spam@merlyn.de mon.co.uk> wrote:
                            [color=blue]
                            > JRS: In article <BD624545.CDE5% ian.sedwell@btc lick.com>, dated Mon, 6
                            > Sep 2004 15:46:19, seen in news:comp.lang. javascript, Ian Sedwell
                            > <ian.sedwell@bt click.com> posted :
                            >[color=green]
                            >> This won't immediately solve your problems, but it will go a long way to
                            >> showing you what's involved. Anyway, it's more fun to do some of the work
                            >> yourselves :-)[/color]
                            >
                            > It seems rather a pointless contribution. Did you write it yourself?[/color]

                            Yes I did.[color=blue]
                            >
                            > Code posted in News should not be allowed to be line-wrapped by the
                            > posting software; the poster should wrap it by hand himself. Or
                            > herself.
                            >[color=green]
                            >> // This function returns the time in 12-hour clock format.[/color]
                            >
                            > A silly thing to do.[/color]

                            Please explain that to my client and everyone else who prefers the 12-hour
                            clock. I prefer the 24-hour clock personally, but then I had it drummed into
                            my head during flying training.[color=blue]
                            >
                            >[color=green]
                            >> // Mos people using this site are not likely to be familiar with the 24-hour
                            >> clock,[/color]
                            >
                            > Most people here know it well; even the Americans.[/color]

                            Why should we expect the Americans to have an inferior intelligence?[color=blue]
                            >
                            >[color=green]
                            >> function showTheHour (theHour) {
                            >> if ((theHour > 0) && (theHour < 13)) {
                            >> return theHour;
                            >> }
                            >> else {
                            >> if (theHour == 0) {
                            >> return theHour;
                            >> }
                            >> else {
                            >> return (theHour - 12);
                            >> }
                            >> }
                            >> }[/color]
                            >
                            > ISTM that the above code does not do the customary thing for the first
                            > hour of the day; but I've not run the code.[/color]

                            It works very well.[color=blue]
                            >
                            >[color=green]
                            >> On 2004/09/06 12:22, in article 14hoj05ti29hh4l b704sb6aek7t4dj lmvv@4ax.com,
                            >> "Otter" <Otter@nospam.n et> wrote:[/color]
                            >
                            > Responses should go after trimmed quotes.
                            >
                            > Carefully reading a newsgroup FAQ before posting to the group is
                            > strongly recommended; anyone who posts an answer palpably inferior to
                            > one indicated by the FAQ is liable to be considered, and described as,
                            > injudicious.
                            >[/color]

                            I hope that no one ever describes you as an arrogant toe-rag. That would be
                            palpably injudicious.

                            Comment

                            • Mick White

                              #15
                              Re: Calculate difference in dates

                              Ian Sedwell wrote:
                              [color=blue][color=green][color=darkred]
                              >>>function showTheHour (theHour) {
                              >>> if ((theHour > 0) && (theHour < 13)) {
                              >>> return theHour;
                              >>> }
                              >>> else {
                              >>> if (theHour == 0) {
                              >>> return theHour;
                              >>> }
                              >>> else {
                              >>> return (theHour - 12);
                              >>> }
                              >>> }
                              >>>}[/color][/color][/color]
                              function showTheHour (theHour){
                              return theHour==0?12:t heHour<13?theHo ur:theHour-12;
                              }

                              If "theHour" is 0, then it is "12" am, no?
                              Mick


                              [color=blue][color=green]
                              >>ISTM that the above code does not do the customary thing for the first
                              >>hour of the day; but I've not run the code.[/color]
                              >
                              >
                              > It works very well.
                              >[color=green]
                              >>[color=darkred]
                              >>>On 2004/09/06 12:22, in article 14hoj05ti29hh4l b704sb6aek7t4dj lmvv@4ax.com,
                              >>>"Otter" <Otter@nospam.n et> wrote:[/color]
                              >>
                              >>Responses should go after trimmed quotes.
                              >>
                              >>Carefully reading a newsgroup FAQ before posting to the group is
                              >>strongly recommended; anyone who posts an answer palpably inferior to
                              >>one indicated by the FAQ is liable to be considered, and described as,
                              >>injudicious .
                              >>[/color]
                              >
                              >
                              > I hope that no one ever describes you as an arrogant toe-rag. That would be
                              > palpably injudicious.
                              >[/color]

                              Comment

                              Working...