Results 1 to 10 of 10

Thread: Get the date and time into one integer

  1. #1
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default Get the date and time into one integer

    Hi,

    I need to get the date and time into an integer.

    GetSystemTime returns something like 301,521,000.... that's milliseconds and thats only 83 hours... what does this mean exactly?
    What I really need is a number that can be converted to the date and time in seconds, i don't need miliseconds.

    Actually something like this would be usefull:
    http://php.net/manual/en/function.time.php

    (but that's PHP )

  2. #2
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    "now" is a double that holds the date and the time, you can decode it using DecodeDate and DecodeTime, that might work for what you want?

  3. #3
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    GetSystemTime is how long you're computer has been running for. I think TheTime and TheDate might be what you're looking for... what are you trying to do with time? You can combine them like this:

    Simba Code:
    var
      TheNow: String;

    TheNow := TheTime + TheDate(Whatever goes here);
    Writeln(TheNow);

    EDIT: Forgot the "The" on the value assignment :S
    Last edited by Runaway; 06-22-2012 at 07:23 PM.

  4. #4
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    yes I will test it but what exactly is a "double"? lol

  5. #5
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by Runaway View Post
    GetSystemTime is how long you're computer has been running for. I think TheTime and TheDate might be what you're looking for... what are you trying to do with time? You can combine them like this:

    Simba Code:
    var
      TheNow: String;

    Now := TheTime + TheDate(Whatever goes here);
    Writeln(TheNow);

    ah okay I understand this now thank you both!

  6. #6
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Simba Code:
    Writeln(TimeRunning)
    That writes how long the script was running.

  7. #7
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by NKN View Post
    Simba Code:
    Writeln(TimeRunning)
    That writes how long the script was running.
    yeah I don't need that because I try two scripts to communicate with eachother And they need to know how late it is and how long ago a message was sent..


    EDIT:

    Interesting....

    Simba Code:
    program New;
      {$i SRL\SRL.simba} // includes all main functions

    begin // ------------ main loop ---------- \\
      SetupSRL; // essential function to make bots work

      writeln(TheTime);
      //writeln(TheDate);

      writeln(Now);
      wait(1000);
      writeln(Now);

      Now
    end.

    returns this:
    Code:
    Compiled successfully in 624 ms.
    SRL Compiled in 15 msec
    09:29:58 PM
    41082.8958119907
    41082.8958235995
    Successfully executed.

    so what does the decimals mean? because it isn't in miliseconds as you can see...




    Edit: found out that a second is about 0.0000115740695.... because this...

    Simba Code:
    program New;
      {$i SRL\SRL.simba} // includes all main functions

      var
       a,b: extended;
      c: integer;

    begin
      SetupSRL; // essential function to make bots work

    for c:= 0 to 60 do
    begin
      a:= Now;
      wait(1000);
      b:= Now;

      writeln(b-a);
    end;

    end.

    returns this:

    Code:
    SRL Compiled in 16 msec
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.0000115740695
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.0000115740695
    0.00001158565282
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001158564555
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.0000115740695
    0.00001158564555
    0.0000115740695
    0.00001157407678
    0.00001158565282
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.00001158565282
    0.0000115740695
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001158565282
    0.00001157407678
    0.0000115740695
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.00001157407678
    0.0000115740695
    0.0000115740695
    0.00001157407678
    0.00001157407678
    Successfully executed.
    uhhh so EXCEL says that the average equals 0.000011575231836333 so a second is 0.000011575231836333....

    Now returns 41082.9062785532....

    41082.9062785532/0.000011575231836333 = 3549208072 , so many seconds is it.


    1 year = 31556926 seconds

    3549208072 / 3549208072 = 112.47001919147429495636133244198

    ahhhhhh so Now has started counting on 1900


    lol


    ah I know how it is... 41082.9110943171 is the time from 1 Januari 1900 in DAYS
    Last edited by Master BAW; 06-22-2012 at 07:53 PM.

  8. #8
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    If you're trying to give an entry in a log a timestamp, you can just use GetSystemTime. That way you won't have to deal with all that junk Now is giving you. Since GetSystemTime will always work (at least when you're running both scripts at the same time) it should be effective. I guess it doesn't work if you are trying to do something long-term though...

    EDIT: Also, what is the problem with using TheTime? Are you having trouble comparing it to other date + time strings?
    Last edited by Runaway; 06-22-2012 at 07:57 PM.

  9. #9
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    You need to use DecodeDate and DecodeTime.

    Something like this (just a small example, prints hours:minutes:seconds(:milliseconds), day.month.year):

    Simba Code:
    function Test: string;
    var
      milliseconds, seconds, minutes, hours, day, month, year: Word;
    begin
      DecodeDate(Now, year, month, day);
      DecodeTime(Now, hours, minutes, seconds, milliseconds);
      Result := (ToStr(hours) + ':' + ToStr(minutes) + ':' + ToStr(seconds) + '(:' + ToStr(milliseconds) + '), ' +
                 ToStr(day) + '.' + ToStr(month) + '.' + ToStr(Year));
    end;

    begin
      WriteLn(Test);
    end.

  10. #10
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Nah I don't need conversion or anything, I made these two little functions and they'll be 100% allright to me because I only need how many minutes from a timepoint it was.

    Simba Code:
    Function Time: integer;
    begin
      Result := round(86400000*Now);//time/date-point in ms
    end;


    Function MinutesFromDate(Date: integer) : integer;
    begin
      Result := floor((Time-Date)/60000);
    end;

    I tested this and it works
    Last edited by Master BAW; 06-26-2012 at 07:14 PM. Reason: testing sig

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •