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

Author Topic: Time Stamp  (Read 2061 times)

0 Members and 1 Guest are viewing this topic.

wickedchew

    Topic Starter


    Rookie
    Time Stamp
    « on: November 09, 2006, 06:37:38 PM »
    Hello,

    I'm trying to mimic the time stamp created by Notepad when pressing the F5 key. The problem is, my command doesn't echo if it is AM or PM. Just the time and date

    echo %TIME:~0,2%.%TIME:~3,2% %DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%

    Time stamp in notepad looks like this: 10:00 AM 11/10/2006
    My command only looks like this: 10:00 11/10/2006

    I want it to be the same as the Notepad's time stamp. Waaaahhhh....  :'(

    ECHO
    "If it's there and you can see it — it's real.

    wickedchew

      Topic Starter


      Rookie
      Re: Time Stamp
      « Reply #1 on: November 09, 2006, 08:19:06 PM »
      I got it! Har har har har...

      -----------------------------------------------

      @echo off
      cls

      set day=AM
      set hrs=%time:~0,2%
      set mins=%TIME:~3,2%

      if %hrs% GTR 12 set day=PM
      if %hrs% EQU 13 set hrs=1
      if %hrs% EQU 14 set hrs=2
      if %hrs% EQU 15 set hrs=3
      if %hrs% EQU 16 set hrs=4
      if %hrs% EQU 17 set hrs=5
      if %hrs% EQU 18 set hrs=6
      if %hrs% EQU 19 set hrs=7
      if %hrs% EQU 20 set hrs=8
      if %hrs% EQU 21 set hrs=9
      if %hrs% EQU 22 set hrs=10
      if %hrs% EQU 23 set hrs=11
      if %hrs% EQU 24 set hrs=12

      echo %hrs%:%mins% %day% %DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%
      pause

      -----------------------------------------------------

      But if the red lines can be shortened, it would be much appreciated.

      ECHO
      "If it's there and you can see it — it's real.

      GuruGary



        Adviser
        Re: Time Stamp
        « Reply #2 on: November 09, 2006, 09:04:48 PM »
        Delete all the red lines, and replace the IF line above them with:
        if %hrs% GTR 12 set day=PM&set /a hrs-=12

        Script would be:
        Code: [Select]
        @echo off
        cls
         
        set day=AM
        set hrs=%time:~0,2%
        set mins=%TIME:~3,2%

        if %hrs% GTR 12 set day=PM&set /a hrs-=12

        echo %hrs%:%mins% %day% %DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%
        pause

        wickedchew

          Topic Starter


          Rookie
          Re: Time Stamp
          « Reply #3 on: November 09, 2006, 09:57:35 PM »
          Thank you so much, oh Great GuruGary! All hail Great Guru! Hail! Hail! Hail!

          I added another line which eliminates the echo of having a 0 hour and edited it to exactly mimic the time stamp of the Notepad.

          ----------------------------
          @echo off
          cls
           
          set day=AM
          set hrs=%time:~0,2%
          set mins=%TIME:~3,2%

          if %hrs% GEQ 12 set day=PM&set /a hrs-=12
          if %hrs% EQU 0 set hrs=12

          echo %hrs%:%mins% %day% %DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%
          pause

          ----------------------------

          Thanks again, oh Great GuruGary!

          ECHO
          "If it's there and you can see it — it's real.