Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Comparing time as a string  (Read 2787 times)

0 Members and 1 Guest are viewing this topic.

Fishing4Truth

  • Guest
Comparing time as a string
« on: August 28, 2007, 01:17:43 PM »
Hello Experts,

I'm tring to check if a file arrives before midnight.  However the "if time equals" does not work.  Here is the relavant section, any suggestions?  Thanks in advance!

:BEGINWAIT
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET TIME=%%A
IF EXIST %PathInbox%\NewFile.DAT GOTO FILEEXIST
IF "%TIME%" == "12:00 AM" GOTO ENDTIMEWAIT

GOTO BEGINWAIT

contrex

  • Guest
Re: Comparing time as a string
« Reply #1 on: August 28, 2007, 01:42:58 PM »
You are going to hit a problem of name collision because %TIME% is already a system variable, (guess what it contains?). Choose a different name eg %mytime%. That should do it.

On my system, right now, %time% reads 20:40:07.47

(I am a euro weenie who uses the 24 hr clock, so time /t produces 20:40)



DeltaSlaya



    Apprentice
  • Google
    Re: Comparing time as a string
    « Reply #2 on: August 28, 2007, 03:12:11 PM »
    If you still need help I'd need to know between what times you'd want it to check. Because it's always before Midnight.
    System specs:
    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
    ASUS Striker Extreme
    XFX 8600GT XXX Edition
    2x 1gB Corsair XMS2 DDR2-800
    Seagate Barracuda 320gB SATA
    Raidmax Ninja 918 (520W ATXV2.0 PSU)
    -

    contrex

    • Guest
    Re: Comparing time as a string
    « Reply #3 on: August 28, 2007, 03:26:29 PM »
    If you still need help I'd need to know between what times you'd want it to check. Because it's always before Midnight.

    Good point Delta. That code must be started manually every day I guess.


    DeltaSlaya



      Apprentice
    • Google
      Re: Comparing time as a string
      « Reply #4 on: August 28, 2007, 03:36:21 PM »
      Well if you're starting it manually it doesn't even need to check the time then, just the existence of the file.
      System specs:
      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
      ASUS Striker Extreme
      XFX 8600GT XXX Edition
      2x 1gB Corsair XMS2 DDR2-800
      Seagate Barracuda 320gB SATA
      Raidmax Ninja 918 (520W ATXV2.0 PSU)
      -

      contrex

      • Guest
      Re: Comparing time as a string
      « Reply #5 on: August 28, 2007, 11:41:02 PM »
      Well if you're starting it manually it doesn't even need to check the time then, just the existence of the file.

      Yes it does, it has to wait around until the next midnight. Did you read the batch code at all?

      DeltaSlaya



        Apprentice
      • Google
        Re: Comparing time as a string
        « Reply #6 on: August 29, 2007, 12:16:33 AM »
        Oh, I see, so it's supposed to loop until the file arrives or the time is midnight? Thats easy enough.
        System specs:
        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
        ASUS Striker Extreme
        XFX 8600GT XXX Edition
        2x 1gB Corsair XMS2 DDR2-800
        Seagate Barracuda 320gB SATA
        Raidmax Ninja 918 (520W ATXV2.0 PSU)
        -

        ghostdog74



          Specialist

          Thanked: 27
          Re: Comparing time as a string
          « Reply #7 on: August 29, 2007, 12:44:05 AM »
          if that's the case, it would be simpler to just schedule a job at or after 12 midnight to query the existence of the file, instead of looping everytime.

          contrex

          • Guest
          Re: Comparing time as a string
          « Reply #8 on: August 29, 2007, 12:48:29 AM »
          As it stands the code decides whether midnight has arrived by looking for "time /t" giving "12:00 AM" as an output. So strictly speaking it is not checking whether midnight has passed, it is checking if it is midnight "now". To be sure of not missing it the code needs to run continuously, which seems a bit inefficient to me. Although once every 30 seconds would still hit the window. More efficient and more elegant to check every once in a while whether midnight has gone past. A challenge might be the time format which depends on locale. (Americans like their AM / PM etc whereas we Euro weenies have our 24 hour format). So I'd store %date% as a string (e.g. set startdate=%date%) and just check every once in a while if it has changed yet (as it does at midnight every day). IF NOT "%startdate%"=="%date%" it's the next day.





          contrex

          • Guest
          Re: Comparing time as a string
          « Reply #9 on: August 29, 2007, 12:49:59 AM »
          if that's the case, it would be simpler to just schedule a job at or after 12 midnight to query the existence of the file, instead of looping everytime.

          Simpler and more logical.