Announcement

Collapse
No announcement yet.

PB Code using System Time

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

  • PB Code using System Time

    I am writing a program using PB and need to call the system time and then add or subtract from it and display it? Anyone have any suggestions or sample code to do this????

  • #2
    Add or subtract what?
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      hours, minutes, seconds. Basically I want to call the system time, save it as an integer and then add or subtract from that number in whatever format I can get it to come up as. Hope that makes sense.

      Comment


      • #4
        Have you considered something along the lines of:
        Code:
        hs = hour * 3600     ' Hours to seconds
        ms = minute * 60    ' Minutes to seconds
        StartTime = hs + ms + seconds
        Do your math thing then convert back to HH:MM:SS.

        Or there may be an API you can use that I don't know about.
        Last edited by Mel Bishop; 21 Feb 2008, 11:32 PM.
        There are no atheists in a fox hole or the morning of a math test.
        If my flag offends you, I'll help you pack.

        Comment


        • #5
          There are a LOT of examples of using the API date functions on the forum. Search for "FILETIME", "Date Routines" or "DateDiff"/"DateAdd".

          Here is one example:

          PowerBASIC and related source code. Please do not post questions or discussions, just source code.
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Why not use my Gregorian Date Library? (see my website).

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              Thanks for the help!!! Will see what I can do with the info.

              Comment


              • #8
                hours, minutes, seconds. Basically I want to call the system time, save it as an integer and then add or subtract from that number in whatever format I can get it to come up as. Hope that makes sense.
                Well, it makes sense in that I understand.. but... that's not what you want to do, that's how you want to do <whatever it is>.

                i.e, there may be a much better way to do what you want to do than adding/subtracting to/from a system time saved as an integer.

                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Egbert Zijlema View Post
                  Why not use my Gregorian Date Library? (see my website).
                  I second that, they are great.

                  Comment


                  • #10
                    Originally posted by Michael Mattias View Post
                    i.e, there may be a much better way to do what you want to do than adding/subtracting to/from a system time saved as an integer.
                    But that's pretty much the recommended way of doing it.

                    From MSDN, structure SYSTEMTIME:
                    It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should
                    • Convert the SYSTEMTIME structure to a FILETIME structure.
                    • Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
                    • Use normal 64-bit arithmetic on the ULARGE_INTEGER value.


                    The system can periodically refresh the time by synchronizing with a time source. Because the system time can be adjusted either forward or backward, do not compare system time readings to determine elapsed time. Instead, use one of the methods described in Windows Time.

                    Comment


                    • #11
                      >But that's pretty much the recommended way of doing it.

                      Yes, that is the way you DO date-time arithmetic.... but I am suggesting you may not need to do that date-time arithmetic.

                      Didn't we have a thread in the last week or two which also started out with doing date-time arithmetic, but the user ended up doing either WM_TIMER or waiting on a WaitableTimer Object?

                      True, doing the date-time arithmetic may be required... then again, it may not.

                      But we just don't know in this case, do we?

                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      Working...
                      X