Announcement

Collapse
No announcement yet.

calculating date/time difference

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • calculating date/time difference

    hi guys, i have a sql statement in code that returns the max date/time from the records (yyyyddmmhhmm)

    my need is to calculate it with time and compare to current date/time and return like 30 mins ago, 20 mins ago... 2 days 11 mins ago...


    any hint?

  • #2
    wounding what the guys are busy with!? nobody tried that!?

    i got some functions from php.net but nothing seems to work here

    any idea will be great

    Comment


    • #3
      You have a very powerful database system at your disposal.

      SELECT
      FLOOR(HOUR(TIMEDIFF(NOW(),(SELECT MAX(date_time_field) FROM your_table))) / 24) AS days,
      MOD(HOUR(TIMEDIFF(NOW(),(SELECT MAX(date_time_field) FROM your_table))), 24) AS hours,
      MINUTE(TIMEDIFF(NOW(),(SELECT MAX(date_time_field) FROM your_table))) AS minutes

      jsb

      Comment


      • #4
        oh, i am so glad just to read your name dude !D I had a feeling you will appear soon though, if you remember, my username was "itsme3" lool

        of course I appreciate your input first, actually managed it this afternoon by (interval) function and i could get output like (2 days 2 hours 50 minutes 2 seconds) which is exactly great and what i wanted... i am fighting now to do it something like 28 hrs 32 mins (i want to get rid of "days") ... so still trying, about 60% there next will try to make it bold for example if more than specific time ... so reading about date parameters... really interesting, but tough and still confusing for me somehow

        again, appreciate your appearance, feeling confident when you are around

        cheers
        Last edited by MikeDE; 11-17-2014, 04:43 PM.

        Comment


        • #5
          here is what i mean by that dear jsb


          Code:
          $datetime1 = new DateTime([glo_field_date]);
          $datetime2 = new DateTime();
          $interval = $datetime1->diff($datetime2);
          $elapsed = $interval->format('%dd %hh %im');
          [glo_new] = $elapsed;

          Comment


          • #6
            MikeDE - so why did you change your username? :-)

            Comment


            • #7
              Well his old name was too confusing. Everybody thought it's him....
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development
              www.scriptcase.eu / www.scriptcase.nl

              Comment


              • #8
                Originally posted by aducom View Post
                Well his old name was too confusing. Everybody thought it's him....
                nice 1 albert

                @adz well, you know bartho for sure, i saw him doing nothing other than "reported to our bugs team" and noticed he is super moderator, so thought to make him do something useful, actually he did after all looooool

                by the way guys, what i reached with this code is nice

                Code:
                $datetime1 = new DateTime([glo_field_date]);
                $datetime2 = new DateTime();
                $interval = $datetime1->diff($datetime2);
                $elapsed = $interval->format('%dd %hh %im');
                [glo_new] = $elapsed;
                i decided to keep it like days, hours, minutes but now trying to format the the output like if more than 10 hours then make it bold... problem that output is not a value that you can put logic (if more than this then do that) i think will try the stackoverflow guys are so active and they've been through hell, if you know how to put the code and ask, you get answer in 5 minutes (so many people), if you don't know how to ask, they will block you loool


                cheers
                Last edited by MikeDE; 11-17-2014, 04:46 PM.

                Comment


                • #9
                  haha albert :-)

                  haha itsme4 :-p

                  Comment


                  • #10
                    Well, since you are so enthusiastic about the object style. :-)

                    Take this.

                    if($interval->h + ($interval->days*24) > 10)
                    {
                    make it bold;
                    }

                    jsb

                    Comment


                    • #11
                      Originally posted by jsbinca View Post
                      Well, since you are so enthusiastic about the object style. :-)

                      Take this.

                      if($interval->h + ($interval->days*24) > 10)
                      {
                      make it bold;
                      }

                      jsb
                      thanks boss, appreciated your ongoing valuable support

                      cheers

                      Comment

                      Working...
                      X