calculate time difference in mintues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • student4lifer@gmail.com

    calculate time difference in mintues

    Hello,

    I have 2 time fields dynamically generated in format "m/d/y H:m".
    Could someone show me a good function to calculate the time interval
    difference in minutes? I played with strtotime() but but that only
    gave me difference in hours and only if the times were on the same day
    (after wrapping with date() function). TIA
  • Jessica Griego

    #2
    Re: calculate time difference in mintues

    <student4lifer@ gmail.comwrote in message
    news:e3d752a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
    Hello,
    >
    I have 2 time fields dynamically generated in format "m/d/y H:m".
    Could someone show me a good function to calculate the time interval
    difference in minutes? I played with strtotime() but but that only
    gave me difference in hours and only if the times were on the same day
    (after wrapping with date() function). TIA
    function dateDiff($first Date, $secondDate, $interval = 'd')
    {
    $swapDate = $firstDate;
    $firstDate = min($swapDate, $secondDate);
    $secondDate = max($swapDate, $secondDate);
    if ($interval == 'm' || $interval == 'y')
    {
    $firstYear = date('Y', $firstDate);
    $secondYear = date('Y', $secondDate);
    $year = $secondYear - $firstYear;
    if ($firstYear != $secondYear){ $year--; }
    if ($interval == 'y'){ return $year; }
    $firstMonth = date('n', $firstDate);
    $secondMonth = date('n', $secondDate);
    $month = $firstYear == $secondYear ?
    abs($firstMonth - $secondMonth) :
    12 - $firstMonth + $secondMonth ;
    return $month % 12 + (12 * $year);
    }
    $intervals = array(
    'w' =(7 * 24 * 60 * 60) ,
    'd' =(24 * 60 * 60) ,
    'h' =(60 * 60) ,
    'n' =60 ,
    's' =1
    );
    return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
    }


    Comment

    • student4lifer@gmail.com

      #3
      Re: calculate time difference in mintues

      On Nov 9, 12:56 am, "Jessica Griego" <j...@example.c omwrote:
      <student4li...@ gmail.comwrote in message
      >
      news:e3d752a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
      >
      Hello,
      >
      I have 2 time fields dynamically generated in format "m/d/y H:m".
      Could someone show me a good function to calculate the time interval
      difference in minutes? I played with strtotime() but but that only
      gave me difference in hours and only if the times were on the same day
      (after wrapping with date() function). TIA
      >
      function dateDiff($first Date, $secondDate, $interval = 'd')
      {
        $swapDate   = $firstDate;
        $firstDate  = min($swapDate, $secondDate);
        $secondDate = max($swapDate, $secondDate);
        if ($interval == 'm' || $interval == 'y')
        {
          $firstYear    = date('Y', $firstDate);
          $secondYear   = date('Y', $secondDate);
          $year         = $secondYear - $firstYear;
          if ($firstYear != $secondYear){ $year--; }
          if ($interval == 'y'){ return $year; }
          $firstMonth   = date('n', $firstDate);
          $secondMonth  = date('n', $secondDate);
          $month        = $firstYear == $secondYear       ?
                          abs($firstMonth - $secondMonth) :
                          12 - $firstMonth + $secondMonth ;
          return $month % 12 + (12 * $year);
        }
        $intervals = array(
                            'w' =(7  * 24 * 60 * 60)  ,
                            'd' =(24 * 60 * 60)       ,
                            'h' =(60 * 60)            ,
                            'n' =60                   ,
                            's' =1
                          );
        return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
      >
      >
      >
      }- Hide quoted text -
      >
      - Show quoted text -
      Thanks...found what I wanted also from date_parse() and
      gregoriantojd() .

      Comment

      • sheldonlg

        #4
        Re: calculate time difference in mintues

        student4lifer@g mail.com wrote:
        Hello,
        >
        I have 2 time fields dynamically generated in format "m/d/y H:m".
        Could someone show me a good function to calculate the time interval
        difference in minutes? I played with strtotime() but but that only
        gave me difference in hours and only if the times were on the same day
        (after wrapping with date() function). TIA

        Wouldn't this work

        $timediff = (strtotime(($da te2) - strtotime($date 1) + 30) / 60

        assuming you want rounding to the nearest minute?

        Comment

        • Jerry Stuckle

          #5
          Re: calculate time difference in mintues

          Jessica Griego wrote:
          <student4lifer@ gmail.comwrote in message
          news:e3d752a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
          >Hello,
          >>
          >I have 2 time fields dynamically generated in format "m/d/y H:m".
          >Could someone show me a good function to calculate the time interval
          >difference in minutes? I played with strtotime() but but that only
          >gave me difference in hours and only if the times were on the same day
          >(after wrapping with date() function). TIA
          >
          function dateDiff($first Date, $secondDate, $interval = 'd')
          {
          $swapDate = $firstDate;
          $firstDate = min($swapDate, $secondDate);
          $secondDate = max($swapDate, $secondDate);
          if ($interval == 'm' || $interval == 'y')
          {
          $firstYear = date('Y', $firstDate);
          $secondYear = date('Y', $secondDate);
          $year = $secondYear - $firstYear;
          if ($firstYear != $secondYear){ $year--; }
          if ($interval == 'y'){ return $year; }
          $firstMonth = date('n', $firstDate);
          $secondMonth = date('n', $secondDate);
          $month = $firstYear == $secondYear ?
          abs($firstMonth - $secondMonth) :
          12 - $firstMonth + $secondMonth ;
          return $month % 12 + (12 * $year);
          }
          $intervals = array(
          'w' =(7 * 24 * 60 * 60) ,
          'd' =(24 * 60 * 60) ,
          'h' =(60 * 60) ,
          'n' =60 ,
          's' =1
          );
          return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
          }
          >
          >
          Which provides incorrect results if it happens to cross an odd number of
          daylight savings time changes.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Jessica Griego

            #6
            Re: calculate time difference in mintues


            "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
            news:gf6o2r$hqd $4@registered.m otzarella.org.. .
            Jessica Griego wrote:
            ><student4lifer @gmail.comwrote in message
            >news:e3d752a 2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
            >>Hello,
            >>>
            >>I have 2 time fields dynamically generated in format "m/d/y H:m".
            >>Could someone show me a good function to calculate the time interval
            >>difference in minutes? I played with strtotime() but but that only
            >>gave me difference in hours and only if the times were on the same day
            >>(after wrapping with date() function). TIA
            >>
            >function dateDiff($first Date, $secondDate, $interval = 'd')
            >{
            > $swapDate = $firstDate;
            > $firstDate = min($swapDate, $secondDate);
            > $secondDate = max($swapDate, $secondDate);
            > if ($interval == 'm' || $interval == 'y')
            > {
            > $firstYear = date('Y', $firstDate);
            > $secondYear = date('Y', $secondDate);
            > $year = $secondYear - $firstYear;
            > if ($firstYear != $secondYear){ $year--; }
            > if ($interval == 'y'){ return $year; }
            > $firstMonth = date('n', $firstDate);
            > $secondMonth = date('n', $secondDate);
            > $month = $firstYear == $secondYear ?
            > abs($firstMonth - $secondMonth) :
            > 12 - $firstMonth + $secondMonth ;
            > return $month % 12 + (12 * $year);
            > }
            > $intervals = array(
            > 'w' =(7 * 24 * 60 * 60) ,
            > 'd' =(24 * 60 * 60) ,
            > 'h' =(60 * 60) ,
            > 'n' =60 ,
            > 's' =1
            > );
            > return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
            >}
            >>
            >>
            >
            Which provides incorrect results if it happens to cross an odd number of
            daylight savings time changes.
            Only if daylight savings time defined for the locale. A simple adjustment
            can be made to offset the difference. No big deal.


            Comment

            • Jerry Stuckle

              #7
              Re: calculate time difference in mintues

              Jessica Griego wrote:
              "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
              news:gf6o2r$hqd $4@registered.m otzarella.org.. .
              >Jessica Griego wrote:
              >><student4life r@gmail.comwrot e in message
              >>news:e3d752 a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
              >>>Hello,
              >>>>
              >>>I have 2 time fields dynamically generated in format "m/d/y H:m".
              >>>Could someone show me a good function to calculate the time interval
              >>>difference in minutes? I played with strtotime() but but that only
              >>>gave me difference in hours and only if the times were on the same day
              >>>(after wrapping with date() function). TIA
              >>function dateDiff($first Date, $secondDate, $interval = 'd')
              >>{
              >> $swapDate = $firstDate;
              >> $firstDate = min($swapDate, $secondDate);
              >> $secondDate = max($swapDate, $secondDate);
              >> if ($interval == 'm' || $interval == 'y')
              >> {
              >> $firstYear = date('Y', $firstDate);
              >> $secondYear = date('Y', $secondDate);
              >> $year = $secondYear - $firstYear;
              >> if ($firstYear != $secondYear){ $year--; }
              >> if ($interval == 'y'){ return $year; }
              >> $firstMonth = date('n', $firstDate);
              >> $secondMonth = date('n', $secondDate);
              >> $month = $firstYear == $secondYear ?
              >> abs($firstMonth - $secondMonth) :
              >> 12 - $firstMonth + $secondMonth ;
              >> return $month % 12 + (12 * $year);
              >> }
              >> $intervals = array(
              >> 'w' =(7 * 24 * 60 * 60) ,
              >> 'd' =(24 * 60 * 60) ,
              >> 'h' =(60 * 60) ,
              >> 'n' =60 ,
              >> 's' =1
              >> );
              >> return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
              >>}
              >>>
              >>>
              >Which provides incorrect results if it happens to cross an odd number of
              >daylight savings time changes.
              >
              Only if daylight savings time defined for the locale. A simple adjustment
              can be made to offset the difference. No big deal.
              >
              >
              Which does not mean your code is correct. It is not.

              Sheldon's answer is much better. No adjustment required.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Jessica Griego

                #8
                Re: calculate time difference in mintues


                "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                news:gf7ss1$44a $3@registered.m otzarella.org.. .
                Jessica Griego wrote:
                >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                >news:gf6o2r$hq d$4@registered. motzarella.org. ..
                >>Jessica Griego wrote:
                >>><student4lif er@gmail.comwro te in message
                >>>news:e3d752a 2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                >>>>Hello,
                >>>>>
                >>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                >>>>Could someone show me a good function to calculate the time interval
                >>>>differenc e in minutes? I played with strtotime() but but that only
                >>>>gave me difference in hours and only if the times were on the same day
                >>>>(after wrapping with date() function). TIA
                >>>function dateDiff($first Date, $secondDate, $interval = 'd')
                >>>{
                >>> $swapDate = $firstDate;
                >>> $firstDate = min($swapDate, $secondDate);
                >>> $secondDate = max($swapDate, $secondDate);
                >>> if ($interval == 'm' || $interval == 'y')
                >>> {
                >>> $firstYear = date('Y', $firstDate);
                >>> $secondYear = date('Y', $secondDate);
                >>> $year = $secondYear - $firstYear;
                >>> if ($firstYear != $secondYear){ $year--; }
                >>> if ($interval == 'y'){ return $year; }
                >>> $firstMonth = date('n', $firstDate);
                >>> $secondMonth = date('n', $secondDate);
                >>> $month = $firstYear == $secondYear ?
                >>> abs($firstMonth - $secondMonth) :
                >>> 12 - $firstMonth + $secondMonth ;
                >>> return $month % 12 + (12 * $year);
                >>> }
                >>> $intervals = array(
                >>> 'w' =(7 * 24 * 60 * 60) ,
                >>> 'd' =(24 * 60 * 60) ,
                >>> 'h' =(60 * 60) ,
                >>> 'n' =60 ,
                >>> 's' =1
                >>> );
                >>> return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
                >>>}
                >>>>
                >>>>
                >>Which provides incorrect results if it happens to cross an odd number of
                >>daylight savings time changes.
                >>
                >Only if daylight savings time defined for the locale. A simple adjustment
                >can be made to offset the difference. No big deal.
                >
                Which does not mean your code is correct. It is not.
                >
                Sheldon's answer is much better. No adjustment required.
                Well first, Mr. Stuckle, I didn't know this was a competition. Second, you
                offer nothing but complaints. At least have the courtesy to 'compete' before
                complaining. Third, mine is absolutely correct outside of DST..even so, as
                I've already mentioned, that is easily handled. Again, no big deal.

                Hat's off to Sheldon. Well done. As for you? Well, 'put up' is about the
                only sentiment I can share with you at this point. If I'm mistaking your
                tone in this posting as childishly arrogant when in fact you are not, I'm
                truly sorry. From what I've just read of your dealings with others in this
                newsgroup, my intuition seems accurate.

                Have a nice day Mr. Stuckle.


                Comment

                • Jerry Stuckle

                  #9
                  Re: calculate time difference in mintues

                  Jessica Griego wrote:
                  "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                  news:gf7ss1$44a $3@registered.m otzarella.org.. .
                  >Jessica Griego wrote:
                  >>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                  >>news:gf6o2r$h qd$4@registered .motzarella.org ...
                  >>>Jessica Griego wrote:
                  >>>><student4li fer@gmail.comwr ote in message
                  >>>>news:e3d752 a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                  >>>>>Hello,
                  >>>>>>
                  >>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                  >>>>>Could someone show me a good function to calculate the time interval
                  >>>>>differen ce in minutes? I played with strtotime() but but that only
                  >>>>>gave me difference in hours and only if the times were on the same day
                  >>>>>(after wrapping with date() function). TIA
                  >>>>function dateDiff($first Date, $secondDate, $interval = 'd')
                  >>>>{
                  >>>> $swapDate = $firstDate;
                  >>>> $firstDate = min($swapDate, $secondDate);
                  >>>> $secondDate = max($swapDate, $secondDate);
                  >>>> if ($interval == 'm' || $interval == 'y')
                  >>>> {
                  >>>> $firstYear = date('Y', $firstDate);
                  >>>> $secondYear = date('Y', $secondDate);
                  >>>> $year = $secondYear - $firstYear;
                  >>>> if ($firstYear != $secondYear){ $year--; }
                  >>>> if ($interval == 'y'){ return $year; }
                  >>>> $firstMonth = date('n', $firstDate);
                  >>>> $secondMonth = date('n', $secondDate);
                  >>>> $month = $firstYear == $secondYear ?
                  >>>> abs($firstMonth - $secondMonth) :
                  >>>> 12 - $firstMonth + $secondMonth ;
                  >>>> return $month % 12 + (12 * $year);
                  >>>> }
                  >>>> $intervals = array(
                  >>>> 'w' =(7 * 24 * 60 * 60) ,
                  >>>> 'd' =(24 * 60 * 60) ,
                  >>>> 'h' =(60 * 60) ,
                  >>>> 'n' =60 ,
                  >>>> 's' =1
                  >>>> );
                  >>>> return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
                  >>>>}
                  >>>>>
                  >>>>>
                  >>>Which provides incorrect results if it happens to cross an odd number of
                  >>>daylight savings time changes.
                  >>Only if daylight savings time defined for the locale. A simple adjustment
                  >>can be made to offset the difference. No big deal.
                  >Which does not mean your code is correct. It is not.
                  >>
                  >Sheldon's answer is much better. No adjustment required.
                  >
                  Well first, Mr. Stuckle, I didn't know this was a competition. Second, you
                  offer nothing but complaints. At least have the courtesy to 'compete' before
                  complaining. Third, mine is absolutely correct outside of DST..even so, as
                  I've already mentioned, that is easily handled. Again, no big deal.
                  >
                  This is not a competition. But if the answer is incorrect, it deserves
                  to be indicated as such.

                  I would have had the same answer as Sheldon, but he beat me to it. And
                  just because yours is "absolutely correct outside of DST" does not make
                  it correct. It's the type of programming (and thinking) which leads to
                  bugs which can be very hard to find.
                  Hat's off to Sheldon. Well done. As for you? Well, 'put up' is about the
                  only sentiment I can share with you at this point. If I'm mistaking your
                  tone in this posting as childishly arrogant when in fact you are not, I'm
                  truly sorry. From what I've just read of your dealings with others in this
                  newsgroup, my intuition seems accurate.
                  >
                  Have a nice day Mr. Stuckle.
                  >
                  >
                  Quite frankly, I really don't give a damn if you "put up" with me or
                  not. There was a problem with you code. I *nicely* called attention to
                  it. Rather than just admit the problem - and bug - you get all upset
                  because someone point out a bug in your code. HOW DARE SOMEONE DO THAT!

                  Get over it.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Jessica Griego

                    #10
                    Re: calculate time difference in mintues


                    "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                    news:gf959q$m89 $1@registered.m otzarella.org.. .
                    Jessica Griego wrote:
                    >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                    >news:gf7ss1$44 a$3@registered. motzarella.org. ..
                    >>Jessica Griego wrote:
                    >>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                    >>>news:gf6o2r$ hqd$4@registere d.motzarella.or g...
                    >>>>Jessica Griego wrote:
                    >>>>><student4l ifer@gmail.comw rote in message
                    >>>>>news:e3d75 2a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                    >>>>>>Hello,
                    >>>>>>>
                    >>>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                    >>>>>>Could someone show me a good function to calculate the time interval
                    >>>>>>differenc e in minutes? I played with strtotime() but but that only
                    >>>>>>gave me difference in hours and only if the times were on the same
                    >>>>>>day
                    >>>>>>(after wrapping with date() function). TIA
                    >>>>>function dateDiff($first Date, $secondDate, $interval = 'd')
                    >>>>>{
                    >>>>> $swapDate = $firstDate;
                    >>>>> $firstDate = min($swapDate, $secondDate);
                    >>>>> $secondDate = max($swapDate, $secondDate);
                    >>>>> if ($interval == 'm' || $interval == 'y')
                    >>>>> {
                    >>>>> $firstYear = date('Y', $firstDate);
                    >>>>> $secondYear = date('Y', $secondDate);
                    >>>>> $year = $secondYear - $firstYear;
                    >>>>> if ($firstYear != $secondYear){ $year--; }
                    >>>>> if ($interval == 'y'){ return $year; }
                    >>>>> $firstMonth = date('n', $firstDate);
                    >>>>> $secondMonth = date('n', $secondDate);
                    >>>>> $month = $firstYear == $secondYear ?
                    >>>>> abs($firstMonth - $secondMonth) :
                    >>>>> 12 - $firstMonth + $secondMonth ;
                    >>>>> return $month % 12 + (12 * $year);
                    >>>>> }
                    >>>>> $intervals = array(
                    >>>>> 'w' =(7 * 24 * 60 * 60) ,
                    >>>>> 'd' =(24 * 60 * 60) ,
                    >>>>> 'h' =(60 * 60) ,
                    >>>>> 'n' =60 ,
                    >>>>> 's' =1
                    >>>>> );
                    >>>>> return floor(abs($firs tDate - $secondDate) /
                    >>>>>$interva ls[$interval]);
                    >>>>>}
                    >>>>>>
                    >>>>>>
                    >>>>Which provides incorrect results if it happens to cross an odd number
                    >>>>of daylight savings time changes.
                    >>>Only if daylight savings time defined for the locale. A simple
                    >>>adjustment can be made to offset the difference. No big deal.
                    >>Which does not mean your code is correct. It is not.
                    >>>
                    >>Sheldon's answer is much better. No adjustment required.
                    >>
                    >Well first, Mr. Stuckle, I didn't know this was a competition. Second,
                    >you offer nothing but complaints. At least have the courtesy to 'compete'
                    >before complaining. Third, mine is absolutely correct outside of
                    >DST..even so, as I've already mentioned, that is easily handled. Again,
                    >no big deal.
                    >>
                    >
                    This is not a competition. But if the answer is incorrect, it deserves to
                    be indicated as such.
                    The answer is correct. It is also an isolated function. That means things
                    like localization functions that specifically deal with DST, what the first
                    day of the week is, etc. handle things like offsetting the results to match
                    what the locale answer should be. As it is, one can easily put an argument
                    in the function the flag whether or not DST is in effect...from there, the
                    math is so glaringly obvious it's not even funny.

                    What I'd expect in 'correction', Jerry, is not just 'Hey, that's wrong'. I'd
                    expect to see an alternative that does exactly what the OP stated without
                    whatever problems you see.
                    I would have had the same answer as Sheldon, but he beat me to it. And
                    just because yours is "absolutely correct outside of DST" does not make it
                    correct. It's the type of programming (and thinking) which leads to bugs
                    which can be very hard to find.
                    You're not even making sense here! It is *absolutely* correct 100% of the
                    time where I live...Arizona! The results make it correct...so, yes, it is
                    correct. Again, if you live somewhere else and find that an adjustment needs
                    to be made to handle DST, then make it.

                    As for Sheldon beating you to it...suuuure, that's the ticket!

                    <snip>
                    Quite frankly, I really don't give a damn if you "put up" with me or not.
                    There was a problem with you code. I *nicely* called attention to it.
                    Rather than just admit the problem - and bug - you get all upset because
                    someone point out a bug in your code. HOW DARE SOMEONE DO THAT!
                    You seem illiterate, Jerry. "Put up" is the predicate to "Shut up". We are
                    all used to putting up with trolls on UseNet. I was saying that you should
                    be able to post a correction rather than just being able to use the word
                    'incorrect'. As for *nicely*, I nicely pointed out that my code is not
                    incorrect and that if someone wants to account for DST because it applies to
                    them, they can and easily. I've said it was no big deal. You keep steering
                    this into an argument. Just drop it.

                    From your other posts in this forum, I too get the feeling you are just a
                    troll. Either drop it, or don't. I'd suggest the former as the latter makes
                    you look childish.

                    EOT


                    Comment

                    • Jerry Stuckle

                      #11
                      Re: calculate time difference in mintues

                      Jessica Griego wrote:
                      "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                      news:gf959q$m89 $1@registered.m otzarella.org.. .
                      >Jessica Griego wrote:
                      >>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                      >>news:gf7ss1$4 4a$3@registered .motzarella.org ...
                      >>>Jessica Griego wrote:
                      >>>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                      >>>>news:gf6o2r $hqd$4@register ed.motzarella.o rg...
                      >>>>>Jessica Griego wrote:
                      >>>>>><student4 lifer@gmail.com wrote in message
                      >>>>>>news:e3d7 52a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                      >>>>>>>Hello,
                      >>>>>>>>
                      >>>>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                      >>>>>>>Could someone show me a good function to calculate the time interval
                      >>>>>>>differen ce in minutes? I played with strtotime() but but that only
                      >>>>>>>gave me difference in hours and only if the times were on the same
                      >>>>>>>day
                      >>>>>>>(after wrapping with date() function). TIA
                      >>>>>>functio n dateDiff($first Date, $secondDate, $interval = 'd')
                      >>>>>>{
                      >>>>>> $swapDate = $firstDate;
                      >>>>>> $firstDate = min($swapDate, $secondDate);
                      >>>>>> $secondDate = max($swapDate, $secondDate);
                      >>>>>> if ($interval == 'm' || $interval == 'y')
                      >>>>>> {
                      >>>>>> $firstYear = date('Y', $firstDate);
                      >>>>>> $secondYear = date('Y', $secondDate);
                      >>>>>> $year = $secondYear - $firstYear;
                      >>>>>> if ($firstYear != $secondYear){ $year--; }
                      >>>>>> if ($interval == 'y'){ return $year; }
                      >>>>>> $firstMonth = date('n', $firstDate);
                      >>>>>> $secondMonth = date('n', $secondDate);
                      >>>>>> $month = $firstYear == $secondYear ?
                      >>>>>> abs($firstMonth - $secondMonth) :
                      >>>>>> 12 - $firstMonth + $secondMonth ;
                      >>>>>> return $month % 12 + (12 * $year);
                      >>>>>> }
                      >>>>>> $intervals = array(
                      >>>>>> 'w' =(7 * 24 * 60 * 60) ,
                      >>>>>> 'd' =(24 * 60 * 60) ,
                      >>>>>> 'h' =(60 * 60) ,
                      >>>>>> 'n' =60 ,
                      >>>>>> 's' =1
                      >>>>>> );
                      >>>>>> return floor(abs($firs tDate - $secondDate) /
                      >>>>>>$interval s[$interval]);
                      >>>>>>}
                      >>>>>>>
                      >>>>>>>
                      >>>>>Which provides incorrect results if it happens to cross an odd number
                      >>>>>of daylight savings time changes.
                      >>>>Only if daylight savings time defined for the locale. A simple
                      >>>>adjustmen t can be made to offset the difference. No big deal.
                      >>>Which does not mean your code is correct. It is not.
                      >>>>
                      >>>Sheldon's answer is much better. No adjustment required.
                      >>Well first, Mr. Stuckle, I didn't know this was a competition. Second,
                      >>you offer nothing but complaints. At least have the courtesy to 'compete'
                      >>before complaining. Third, mine is absolutely correct outside of
                      >>DST..even so, as I've already mentioned, that is easily handled. Again,
                      >>no big deal.
                      >>>
                      >This is not a competition. But if the answer is incorrect, it deserves to
                      >be indicated as such.
                      >
                      The answer is correct. It is also an isolated function. That means things
                      like localization functions that specifically deal with DST, what the first
                      day of the week is, etc. handle things like offsetting the results to match
                      what the locale answer should be. As it is, one can easily put an argument
                      in the function the flag whether or not DST is in effect...from there, the
                      math is so glaringly obvious it's not even funny.
                      >
                      What I'd expect in 'correction', Jerry, is not just 'Hey, that's wrong'. I'd
                      expect to see an alternative that does exactly what the OP stated without
                      whatever problems you see.
                      >
                      Sorry, the answer is not correct - for the exact reason I outlined. It
                      does not work when the daylight savings time crosses an odd number of
                      DST changes.

                      You did not point out how to handle offsetting the results, nor did your
                      code contain any way to handle this occurrence.

                      And I did point out a valid answer - the one from Sheldon, which is the
                      same one I would have posted. And it does not suffer from the DST problem.

                      >I would have had the same answer as Sheldon, but he beat me to it. And
                      >just because yours is "absolutely correct outside of DST" does not make it
                      >correct. It's the type of programming (and thinking) which leads to bugs
                      >which can be very hard to find.
                      >
                      You're not even making sense here! It is *absolutely* correct 100% of the
                      time where I live...Arizona! The results make it correct...so, yes, it is
                      correct. Again, if you live somewhere else and find that an adjustment needs
                      to be made to handle DST, then make it.
                      >
                      That's fine - in Arizona you do not (currently) observe DST. That does
                      not make it correct for the rest of the world!
                      As for Sheldon beating you to it...suuuure, that's the ticket!
                      >
                      Yep. I'm not on here 24/7. But if I would have seen that post before
                      Sheldon did, I would have presented roughly the same solution.
                      <snip>
                      >
                      >Quite frankly, I really don't give a damn if you "put up" with me or not.
                      >There was a problem with you code. I *nicely* called attention to it.
                      >Rather than just admit the problem - and bug - you get all upset because
                      >someone point out a bug in your code. HOW DARE SOMEONE DO THAT!
                      >
                      You seem illiterate, Jerry. "Put up" is the predicate to "Shut up". We are
                      all used to putting up with trolls on UseNet. I was saying that you should
                      be able to post a correction rather than just being able to use the word
                      'incorrect'. As for *nicely*, I nicely pointed out that my code is not
                      incorrect and that if someone wants to account for DST because it applies to
                      them, they can and easily. I've said it was no big deal. You keep steering
                      this into an argument. Just drop it.
                      >
                      You don't seem to understand plain English. But then most trolls don't.
                      And there's only one troll here - YOU.

                      I did post a correction. I pointed out what was wrong with your code
                      and pointed to Sheldon's solution as the correct one. I saw no reason
                      to post the same code a second time.
                      From your other posts in this forum, I too get the feeling you are just a
                      troll. Either drop it, or don't. I'd suggest the former as the latter makes
                      you look childish.
                      >
                      EOT
                      >
                      >
                      You're the only one acting childish here - insisting your code is
                      correct when it isn't - for the very solid reason I gave.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Jessica Griego

                        #12
                        Re: calculate time difference in mintues


                        "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                        news:gf7ss1$44a $3@registered.m otzarella.org.. .
                        Jessica Griego wrote:
                        >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                        >news:gf6o2r$hq d$4@registered. motzarella.org. ..
                        >>Jessica Griego wrote:
                        >>><student4lif er@gmail.comwro te in message
                        >>>news:e3d752a 2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                        >>>>Hello,
                        >>>>>
                        >>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                        >>>>Could someone show me a good function to calculate the time interval
                        >>>>differenc e in minutes? I played with strtotime() but but that only
                        >>>>gave me difference in hours and only if the times were on the same day
                        >>>>(after wrapping with date() function). TIA
                        >>>function dateDiff($first Date, $secondDate, $interval = 'd')
                        >>>{
                        >>> $swapDate = $firstDate;
                        >>> $firstDate = min($swapDate, $secondDate);
                        >>> $secondDate = max($swapDate, $secondDate);
                        >>> if ($interval == 'm' || $interval == 'y')
                        >>> {
                        >>> $firstYear = date('Y', $firstDate);
                        >>> $secondYear = date('Y', $secondDate);
                        >>> $year = $secondYear - $firstYear;
                        >>> if ($firstYear != $secondYear){ $year--; }
                        >>> if ($interval == 'y'){ return $year; }
                        >>> $firstMonth = date('n', $firstDate);
                        >>> $secondMonth = date('n', $secondDate);
                        >>> $month = $firstYear == $secondYear ?
                        >>> abs($firstMonth - $secondMonth) :
                        >>> 12 - $firstMonth + $secondMonth ;
                        >>> return $month % 12 + (12 * $year);
                        >>> }
                        >>> $intervals = array(
                        >>> 'w' =(7 * 24 * 60 * 60) ,
                        >>> 'd' =(24 * 60 * 60) ,
                        >>> 'h' =(60 * 60) ,
                        >>> 'n' =60 ,
                        >>> 's' =1
                        >>> );
                        >>> return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
                        >>>}
                        >>>>
                        >>>>
                        >>Which provides incorrect results if it happens to cross an odd number of
                        >>daylight savings time changes.
                        >>
                        >Only if daylight savings time defined for the locale. A simple adjustment
                        >can be made to offset the difference. No big deal.
                        >
                        Which does not mean your code is correct. It is not.
                        >
                        Sheldon's answer is much better. No adjustment required.
                        Now that I've looked at this, Jerry, please tell me the difference between
                        this:

                        (strtotime($dat e2) - strtotime($date 1) + 30) / 60
                        // Notice that Sheldon didn't test his suggestion...
                        // which would have blown up because of the extra '('
                        // in it that I removed above.
                        // You apparently did not test it either.

                        And this:

                        abs($firstDate - $secondDate) / $intervals[$interval])
                        // Where the date variables above are already time...
                        // and are being divided by 60 ('n' for minutes for the interval).

                        Seems that not only is mine correct, it matches Sheldon's identically -
                        minus his 30 second rounding - but that I actually posted mine first AND
                        tested it. Your support for Sheldon's code was that it handled DST. It does
                        not. I expect to see your DST enabled version now. That, or a post saying
                        "I, Jerry Stuckle, am pompous and brash."

                        BTW, I know what Sheldon is going for, however I don't think you do nor can
                        you make a simple correction to his code that will make it DST enabled.
                        We'll see.

                        :^)


                        Comment

                        • Jessica Griego

                          #13
                          Re: calculate time difference in mintues


                          "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          news:gf9jad$nn4 $1@registered.m otzarella.org.. .
                          Jessica Griego wrote:
                          >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          >news:gf959q$m8 9$1@registered. motzarella.org. ..
                          >>Jessica Griego wrote:
                          >>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          >>>news:gf7ss1$ 44a$3@registere d.motzarella.or g...
                          >>>>Jessica Griego wrote:
                          >>>>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          >>>>>news:gf6o2 r$hqd$4@registe red.motzarella. org...
                          >>>>>>Jessica Griego wrote:
                          >>>>>>><student 4lifer@gmail.co mwrote in message
                          >>>>>>>news:e3d 752a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                          >>>>>>>>Hello ,
                          >>>>>>>>>
                          >>>>>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                          >>>>>>>>Could someone show me a good function to calculate the time
                          >>>>>>>>interva l
                          >>>>>>>>differe nce in minutes? I played with strtotime() but but that only
                          >>>>>>>>gave me difference in hours and only if the times were on the same
                          >>>>>>>>day
                          >>>>>>>>(afte r wrapping with date() function). TIA
                          >>>>>>>functi on dateDiff($first Date, $secondDate, $interval = 'd')
                          >>>>>>>{
                          >>>>>>> $swapDate = $firstDate;
                          >>>>>>> $firstDate = min($swapDate, $secondDate);
                          >>>>>>> $secondDate = max($swapDate, $secondDate);
                          >>>>>>> if ($interval == 'm' || $interval == 'y')
                          >>>>>>> {
                          >>>>>>> $firstYear = date('Y', $firstDate);
                          >>>>>>> $secondYear = date('Y', $secondDate);
                          >>>>>>> $year = $secondYear - $firstYear;
                          >>>>>>> if ($firstYear != $secondYear){ $year--; }
                          >>>>>>> if ($interval == 'y'){ return $year; }
                          >>>>>>> $firstMonth = date('n', $firstDate);
                          >>>>>>> $secondMonth = date('n', $secondDate);
                          >>>>>>> $month = $firstYear == $secondYear ?
                          >>>>>>> abs($firstMonth - $secondMonth) :
                          >>>>>>> 12 - $firstMonth + $secondMonth ;
                          >>>>>>> return $month % 12 + (12 * $year);
                          >>>>>>> }
                          >>>>>>> $intervals = array(
                          >>>>>>> 'w' =(7 * 24 * 60 * 60) ,
                          >>>>>>> 'd' =(24 * 60 * 60) ,
                          >>>>>>> 'h' =(60 * 60) ,
                          >>>>>>> 'n' =60 ,
                          >>>>>>> 's' =1
                          >>>>>>> );
                          >>>>>>> return floor(abs($firs tDate - $secondDate) /
                          >>>>>>>$interva ls[$interval]);
                          >>>>>>>}
                          >>>>>>>>
                          >>>>>>>>
                          >>>>>>Which provides incorrect results if it happens to cross an odd
                          >>>>>>number of daylight savings time changes.
                          >>>>>Only if daylight savings time defined for the locale. A simple
                          >>>>>adjustme nt can be made to offset the difference. No big deal.
                          >>>>Which does not mean your code is correct. It is not.
                          >>>>>
                          >>>>Sheldon's answer is much better. No adjustment required.
                          >>>Well first, Mr. Stuckle, I didn't know this was a competition. Second,
                          >>>you offer nothing but complaints. At least have the courtesy to
                          >>>'compete' before complaining. Third, mine is absolutely correct outside
                          >>>of DST..even so, as I've already mentioned, that is easily handled.
                          >>>Again, no big deal.
                          >>>>
                          >>This is not a competition. But if the answer is incorrect, it deserves
                          >>to be indicated as such.
                          >>
                          >The answer is correct. It is also an isolated function. That means things
                          >like localization functions that specifically deal with DST, what the
                          >first day of the week is, etc. handle things like offsetting the results
                          >to match what the locale answer should be. As it is, one can easily put
                          >an argument in the function the flag whether or not DST is in
                          >effect...fro m there, the math is so glaringly obvious it's not even
                          >funny.
                          >>
                          >What I'd expect in 'correction', Jerry, is not just 'Hey, that's wrong'.
                          >I'd expect to see an alternative that does exactly what the OP stated
                          >without whatever problems you see.
                          >>
                          >
                          Sorry, the answer is not correct - for the exact reason I outlined. It
                          does not work when the daylight savings time crosses an odd number of DST
                          changes.
                          Sorry, in Arizona we don't use DST...my results are ALWAYS correct. If you
                          use DST, adjust for it yourself.
                          You did not point out how to handle offsetting the results, nor did your
                          code contain any way to handle this occurrence.
                          Because in the code lib in which I have it, I have a localization class that
                          adjusts not only for DST, but also for the beginning of the week - for when
                          this function is asked to return the difference of two dates in weeks...you
                          weren't smart enough to catch that either!

                          This function does exactly what I want it to do and returns consistently
                          correct results. As it is, Jerry, you can't seem to even muster a '$' sign
                          of code. Further, if you are going to argue the fact that I don't show *how*
                          to adjust for DST, it means you probably don't have a CLUE as to how to do
                          it! That's funny to me, since it's about as easy as 2 and 2. That's ok, I'll
                          mute my troll meter at this point since that seems it's all you're doing.
                          And I did point out a valid answer - the one from Sheldon, which is the
                          same one I would have posted. And it does not suffer from the DST
                          problem.
                          Actually, not only will it cause php to explode as it is written, it will
                          NOT handle DST...as written. Had you, or he, actually tested it you'd know
                          that it doesn't. Further, you don't know what to do to correct Sheldon's
                          oversight so that it does work...but I'm sure Sheldon does! You make me
                          laugh. :^)
                          >>I would have had the same answer as Sheldon, but he beat me to it. And
                          >>just because yours is "absolutely correct outside of DST" does not make
                          >>it correct. It's the type of programming (and thinking) which leads to
                          >>bugs which can be very hard to find.
                          >>
                          >You're not even making sense here! It is *absolutely* correct 100% of the
                          >time where I live...Arizona! The results make it correct...so, yes, it is
                          >correct. Again, if you live somewhere else and find that an adjustment
                          >needs to be made to handle DST, then make it.
                          >>
                          >
                          That's fine - in Arizona you do not (currently) observe DST. That does
                          not make it correct for the rest of the world!
                          It make it correct THE WORLD OVER when NOT IN DST !!! It also makes it VERY
                          easy to offset when the WORLD IS IN DST. I have a localization class that
                          works all of that out very nicely.
                          >As for Sheldon beating you to it...suuuure, that's the ticket!
                          >>
                          >
                          Yep. I'm not on here 24/7. But if I would have seen that post before
                          Sheldon did, I would have presented roughly the same solution.
                          From what I can tell, you're here 23.75/7 annoying the hell out of most of
                          UseNet.
                          ><snip>
                          >>
                          >>Quite frankly, I really don't give a damn if you "put up" with me or
                          >>not. There was a problem with you code. I *nicely* called attention to
                          >>it. Rather than just admit the problem - and bug - you get all upset
                          >>because someone point out a bug in your code. HOW DARE SOMEONE DO THAT!
                          >>
                          >You seem illiterate, Jerry. "Put up" is the predicate to "Shut up". We
                          >are all used to putting up with trolls on UseNet. I was saying that you
                          >should be able to post a correction rather than just being able to use
                          >the word 'incorrect'. As for *nicely*, I nicely pointed out that my code
                          >is not incorrect and that if someone wants to account for DST because it
                          >applies to them, they can and easily. I've said it was no big deal. You
                          >keep steering this into an argument. Just drop it.
                          >>
                          >
                          You don't seem to understand plain English. But then most trolls don't.
                          And there's only one troll here - YOU.
                          Lol. So, your lack of rebuttal is to make a strong case for your literacy?
                          "I'm rubber and you're glue"...that's to make you appear sophisticated and
                          NOT a troll.
                          I did post a correction. I pointed out what was wrong with your code and
                          pointed to Sheldon's solution as the correct one. I saw no reason to post
                          the same code a second time.
                          >
                          >From your other posts in this forum, I too get the feeling you are just a
                          >troll. Either drop it, or don't. I'd suggest the former as the latter
                          >makes you look childish.
                          >>
                          >EOT
                          >
                          You're the only one acting childish here - insisting your code is correct
                          when it isn't - for the very solid reason I gave.
                          The code is correct. And as written, Sheldon's is not...and you don't even
                          know why.

                          You obviously think as a child. It also effects your behavior and not just
                          your logical processes.

                          **PLONK**

                          No more trolling for you. :)


                          Comment

                          • Jerry Stuckle

                            #14
                            Re: calculate time difference in mintues

                            Jessica Griego wrote:
                            "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                            news:gf9jad$nn4 $1@registered.m otzarella.org.. .
                            >Jessica Griego wrote:
                            >>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                            >>news:gf959q$m 89$1@registered .motzarella.org ...
                            >>>Jessica Griego wrote:
                            >>>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                            >>>>news:gf7ss1 $44a$3@register ed.motzarella.o rg...
                            >>>>>Jessica Griego wrote:
                            >>>>>>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                            >>>>>>news:gf6o 2r$hqd$4@regist ered.motzarella .org...
                            >>>>>>>Jessic a Griego wrote:
                            >>>>>>>><studen t4lifer@gmail.c omwrote in message
                            >>>>>>>>news:e3 d752a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                            >>>>>>>>>Hell o,
                            >>>>>>>>>>
                            >>>>>>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                            >>>>>>>>>Coul d someone show me a good function to calculate the time
                            >>>>>>>>>interv al
                            >>>>>>>>>differ ence in minutes? I played with strtotime() but but that only
                            >>>>>>>>>gave me difference in hours and only if the times were on the same
                            >>>>>>>>>day
                            >>>>>>>>>(aft er wrapping with date() function). TIA
                            >>>>>>>>functio n dateDiff($first Date, $secondDate, $interval = 'd')
                            >>>>>>>>{
                            >>>>>>>> $swapDate = $firstDate;
                            >>>>>>>> $firstDate = min($swapDate, $secondDate);
                            >>>>>>>> $secondDate = max($swapDate, $secondDate);
                            >>>>>>>> if ($interval == 'm' || $interval == 'y')
                            >>>>>>>> {
                            >>>>>>>> $firstYear = date('Y', $firstDate);
                            >>>>>>>> $secondYear = date('Y', $secondDate);
                            >>>>>>>> $year = $secondYear - $firstYear;
                            >>>>>>>> if ($firstYear != $secondYear){ $year--; }
                            >>>>>>>> if ($interval == 'y'){ return $year; }
                            >>>>>>>> $firstMonth = date('n', $firstDate);
                            >>>>>>>> $secondMonth = date('n', $secondDate);
                            >>>>>>>> $month = $firstYear == $secondYear ?
                            >>>>>>>> abs($firstMonth - $secondMonth) :
                            >>>>>>>> 12 - $firstMonth + $secondMonth ;
                            >>>>>>>> return $month % 12 + (12 * $year);
                            >>>>>>>> }
                            >>>>>>>> $intervals = array(
                            >>>>>>>> 'w' =(7 * 24 * 60 * 60) ,
                            >>>>>>>> 'd' =(24 * 60 * 60) ,
                            >>>>>>>> 'h' =(60 * 60) ,
                            >>>>>>>> 'n' =60 ,
                            >>>>>>>> 's' =1
                            >>>>>>>> );
                            >>>>>>>> return floor(abs($firs tDate - $secondDate) /
                            >>>>>>>>$interv als[$interval]);
                            >>>>>>>>}
                            >>>>>>>>>
                            >>>>>>>>>
                            >>>>>>>Which provides incorrect results if it happens to cross an odd
                            >>>>>>>number of daylight savings time changes.
                            >>>>>>Only if daylight savings time defined for the locale. A simple
                            >>>>>>adjustmen t can be made to offset the difference. No big deal.
                            >>>>>Which does not mean your code is correct. It is not.
                            >>>>>>
                            >>>>>Sheldon' s answer is much better. No adjustment required.
                            >>>>Well first, Mr. Stuckle, I didn't know this was a competition. Second,
                            >>>>you offer nothing but complaints. At least have the courtesy to
                            >>>>'compete' before complaining. Third, mine is absolutely correct outside
                            >>>>of DST..even so, as I've already mentioned, that is easily handled.
                            >>>>Again, no big deal.
                            >>>>>
                            >>>This is not a competition. But if the answer is incorrect, it deserves
                            >>>to be indicated as such.
                            >>The answer is correct. It is also an isolated function. That means things
                            >>like localization functions that specifically deal with DST, what the
                            >>first day of the week is, etc. handle things like offsetting the results
                            >>to match what the locale answer should be. As it is, one can easily put
                            >>an argument in the function the flag whether or not DST is in
                            >>effect...fr om there, the math is so glaringly obvious it's not even
                            >>funny.
                            >>>
                            >>What I'd expect in 'correction', Jerry, is not just 'Hey, that's wrong'.
                            >>I'd expect to see an alternative that does exactly what the OP stated
                            >>without whatever problems you see.
                            >>>
                            >Sorry, the answer is not correct - for the exact reason I outlined. It
                            >does not work when the daylight savings time crosses an odd number of DST
                            >changes.
                            >
                            Sorry, in Arizona we don't use DST...my results are ALWAYS correct. If you
                            use DST, adjust for it yourself.
                            >
                            YOU presented an incorrect solution. Period.
                            >You did not point out how to handle offsetting the results, nor did your
                            >code contain any way to handle this occurrence.
                            >
                            Because in the code lib in which I have it, I have a localization class that
                            adjusts not only for DST, but also for the beginning of the week - for when
                            this function is asked to return the difference of two dates in weeks...you
                            weren't smart enough to catch that either!
                            >
                            Then that's the code you should have posted.
                            This function does exactly what I want it to do and returns consistently
                            correct results. As it is, Jerry, you can't seem to even muster a '$' sign
                            of code. Further, if you are going to argue the fact that I don't show *how*
                            to adjust for DST, it means you probably don't have a CLUE as to how to do
                            it! That's funny to me, since it's about as easy as 2 and 2. That's ok, I'll
                            mute my troll meter at this point since that seems it's all you're doing.
                            >
                            No, it does not return "consistent ly correct results" when the time
                            period spans an odd number of standard/daylight savings time changes.

                            It's just this type of thinking which produces hard to find errors in code.
                            >And I did point out a valid answer - the one from Sheldon, which is the
                            >same one I would have posted. And it does not suffer from the DST
                            >problem.
                            >
                            Actually, not only will it cause php to explode as it is written, it will
                            NOT handle DST...as written. Had you, or he, actually tested it you'd know
                            that it doesn't. Further, you don't know what to do to correct Sheldon's
                            oversight so that it does work...but I'm sure Sheldon does! You make me
                            laugh. :^)
                            >
                            No, it will not "cause php to explode". And it will handle DST, as written.

                            But we already know what kind of programmer you are.
                            >>>I would have had the same answer as Sheldon, but he beat me to it. And
                            >>>just because yours is "absolutely correct outside of DST" does not make
                            >>>it correct. It's the type of programming (and thinking) which leads to
                            >>>bugs which can be very hard to find.
                            >>You're not even making sense here! It is *absolutely* correct 100% of the
                            >>time where I live...Arizona! The results make it correct...so, yes, it is
                            >>correct. Again, if you live somewhere else and find that an adjustment
                            >>needs to be made to handle DST, then make it.
                            >>>
                            >That's fine - in Arizona you do not (currently) observe DST. That does
                            >not make it correct for the rest of the world!
                            >
                            It make it correct THE WORLD OVER when NOT IN DST !!! It also makes it VERY
                            easy to offset when the WORLD IS IN DST. I have a localization class that
                            works all of that out very nicely.
                            >
                            So? There is a significant part of the world WHICH USES DST. And your
                            code, AS WRITTEN, does not handle that.
                            >>As for Sheldon beating you to it...suuuure, that's the ticket!
                            >>>
                            >Yep. I'm not on here 24/7. But if I would have seen that post before
                            >Sheldon did, I would have presented roughly the same solution.
                            >
                            From what I can tell, you're here 23.75/7 annoying the hell out of most of
                            UseNet.
                            >
                            ROFLMAO! Because I call attention to the sloppy code trolls like you
                            write, and indicate WHY it is wrong?
                            >><snip>
                            >>>
                            >>>Quite frankly, I really don't give a damn if you "put up" with me or
                            >>>not. There was a problem with you code. I *nicely* called attention to
                            >>>it. Rather than just admit the problem - and bug - you get all upset
                            >>>because someone point out a bug in your code. HOW DARE SOMEONE DO THAT!
                            >>You seem illiterate, Jerry. "Put up" is the predicate to "Shut up". We
                            >>are all used to putting up with trolls on UseNet. I was saying that you
                            >>should be able to post a correction rather than just being able to use
                            >>the word 'incorrect'. As for *nicely*, I nicely pointed out that my code
                            >>is not incorrect and that if someone wants to account for DST because it
                            >>applies to them, they can and easily. I've said it was no big deal. You
                            >>keep steering this into an argument. Just drop it.
                            >>>
                            >You don't seem to understand plain English. But then most trolls don't.
                            >And there's only one troll here - YOU.
                            >
                            Lol. So, your lack of rebuttal is to make a strong case for your literacy?
                            "I'm rubber and you're glue"...that's to make you appear sophisticated and
                            NOT a troll.
                            >
                            ROFLMAO!
                            >I did post a correction. I pointed out what was wrong with your code and
                            >pointed to Sheldon's solution as the correct one. I saw no reason to post
                            >the same code a second time.
                            >>
                            >>From your other posts in this forum, I too get the feeling you are just a
                            >>troll. Either drop it, or don't. I'd suggest the former as the latter
                            >>makes you look childish.
                            >>>
                            >>EOT
                            >You're the only one acting childish here - insisting your code is correct
                            >when it isn't - for the very solid reason I gave.
                            >
                            The code is correct. And as written, Sheldon's is not...and you don't even
                            know why.
                            >
                            You obviously think as a child. It also effects your behavior and not just
                            your logical processes.
                            >
                            **PLONK**
                            >
                            No more trolling for you. :)
                            >
                            >
                            You obviously have no real experience in a serious programming
                            environment. Your code is sloppy and error-prone. I suspect your only
                            "experience " is writing sloppy PHP code for the web and hoping it will work.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • Jerry Stuckle

                              #15
                              Re: calculate time difference in mintues

                              Jessica Griego wrote:
                              "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                              news:gf7ss1$44a $3@registered.m otzarella.org.. .
                              >Jessica Griego wrote:
                              >>"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                              >>news:gf6o2r$h qd$4@registered .motzarella.org ...
                              >>>Jessica Griego wrote:
                              >>>><student4li fer@gmail.comwr ote in message
                              >>>>news:e3d752 a2-7754-472f-8eac-75a1095d2085@v3 9g2000pro.googl egroups.com...
                              >>>>>Hello,
                              >>>>>>
                              >>>>>I have 2 time fields dynamically generated in format "m/d/y H:m".
                              >>>>>Could someone show me a good function to calculate the time interval
                              >>>>>differen ce in minutes? I played with strtotime() but but that only
                              >>>>>gave me difference in hours and only if the times were on the same day
                              >>>>>(after wrapping with date() function). TIA
                              >>>>function dateDiff($first Date, $secondDate, $interval = 'd')
                              >>>>{
                              >>>> $swapDate = $firstDate;
                              >>>> $firstDate = min($swapDate, $secondDate);
                              >>>> $secondDate = max($swapDate, $secondDate);
                              >>>> if ($interval == 'm' || $interval == 'y')
                              >>>> {
                              >>>> $firstYear = date('Y', $firstDate);
                              >>>> $secondYear = date('Y', $secondDate);
                              >>>> $year = $secondYear - $firstYear;
                              >>>> if ($firstYear != $secondYear){ $year--; }
                              >>>> if ($interval == 'y'){ return $year; }
                              >>>> $firstMonth = date('n', $firstDate);
                              >>>> $secondMonth = date('n', $secondDate);
                              >>>> $month = $firstYear == $secondYear ?
                              >>>> abs($firstMonth - $secondMonth) :
                              >>>> 12 - $firstMonth + $secondMonth ;
                              >>>> return $month % 12 + (12 * $year);
                              >>>> }
                              >>>> $intervals = array(
                              >>>> 'w' =(7 * 24 * 60 * 60) ,
                              >>>> 'd' =(24 * 60 * 60) ,
                              >>>> 'h' =(60 * 60) ,
                              >>>> 'n' =60 ,
                              >>>> 's' =1
                              >>>> );
                              >>>> return floor(abs($firs tDate - $secondDate) / $intervals[$interval]);
                              >>>>}
                              >>>>>
                              >>>>>
                              >>>Which provides incorrect results if it happens to cross an odd number of
                              >>>daylight savings time changes.
                              >>Only if daylight savings time defined for the locale. A simple adjustment
                              >>can be made to offset the difference. No big deal.
                              >Which does not mean your code is correct. It is not.
                              >>
                              >Sheldon's answer is much better. No adjustment required.
                              >
                              Now that I've looked at this, Jerry, please tell me the difference between
                              this:
                              >
                              (strtotime($dat e2) - strtotime($date 1) + 30) / 60
                              // Notice that Sheldon didn't test his suggestion...
                              // which would have blown up because of the extra '('
                              // in it that I removed above.
                              // You apparently did not test it either.
                              >
                              And this:
                              >
                              abs($firstDate - $secondDate) / $intervals[$interval])
                              // Where the date variables above are already time...
                              // and are being divided by 60 ('n' for minutes for the interval).
                              >
                              Seems that not only is mine correct, it matches Sheldon's identically -
                              minus his 30 second rounding - but that I actually posted mine first AND
                              tested it. Your support for Sheldon's code was that it handled DST. It does
                              not. I expect to see your DST enabled version now. That, or a post saying
                              "I, Jerry Stuckle, am pompous and brash."
                              >
                              BTW, I know what Sheldon is going for, however I don't think you do nor can
                              you make a simple correction to his code that will make it DST enabled.
                              We'll see.
                              >
                              :^)
                              >
                              >

                              ROFLMAO. A minor syntax error does not make the idea invalid - unlike
                              your code.

                              And obviously you did NOT check his code versus your across a
                              standard/daylight savings time change - or you would have found the
                              difference.

                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...