1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

save current date

Discussion in 'All Other Software' started by terryflan, Aug 7, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. terryflan

    terryflan Thread Starter

    Joined:
    Aug 7, 2007
    Messages:
    11
    I need a small batch file to read and save my current date, then change the date to 1/6/2003, then run a program, when program ends then restore original date.
    I managed most of it but cannot store date or restore.
    Hope you can help, you should see the errors I get on internet when I forget to change the date back.
    terry
     
  2. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Terry,

    Here's a batch file that should do what you want. Be sure to change the program name from notepad to yours.

    Be aware that if your program finishes after midnight, your computer will be a day behind, eg, start at 11:55 PM 08/07/2007, finish at 12:05 AM 08/08/2007, your computer will be set to 12:05 AM 08/07/2007. It is possible to check for that, as well as correctly setting the date after a power failure, but gets a bit more complex :)

    You didn't state what your OS was, but this works in WinXP SP1 and SP2, and Win2K SP4

    Start of Batch File
    @Rem Create an environment variable equal to todays date.
    @Rem The :~4 skips the Day abreviation - See "Environment variable substitution" under help for the SET command (set /?)

    @set TDDATE=%DATE:~4%

    @Rem set system date to 1/6/2003

    @date 01/06/2003

    @Rem Run program and wait for it to finish

    @start /wait notepad.exe

    @Rem Set the date back to the saved value

    @date %TDDATE%

    @Rem Delete the environment variable

    @SET TDDATE=

    End of Batch File
     
  3. terryflan

    terryflan Thread Starter

    Joined:
    Aug 7, 2007
    Messages:
    11
    Hi Outcaste
    I thank you for the file.
    It changes the date to 2003 ok, and opens program.
    But when the program ends I get this message.

    The system cannot accept the date entered.
    Enter the new date :(dd-mm-yy)

    If I now enter 08/08/07 or 08-08-07 for eg it accepts it.
    Any more ideas?

    Terry
     
  4. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Got a few ideas, #3 the most likely

    1. You're running Win95, 98, or Me. I don't think they support the Command Extensions that make this method work, or at least they need to be turned on first; WinNT 4.0 SP6a, Win2K, and WinXP do and they are on by default. Check this by typing set /? as described in #2

    2. You have Command Extensions turned off. You can check this by typing set /? at a command prompt, if they are off you'll see about 5 lines of text and command extensions won't be mentioned; if they are on, there will be several pages of info, and command extensions is mentioned in the 6th line of text.

    3. A typo, probably in the first set line @set TDDATE=%DATE:~4% -- it's a colon, not a semicolon, and a tilde, not a minus.

    4. The program you are running just happens to use an environment variable named TDDATE and is changing it on us.

    Possible Solutions:
    #1. Let me know which OS you are running. If Win9x or WinMe, type command /? > cmdhelp.txt and send me that file.

    #2. If Command Extensions are off, we can either edit the registry to turn them on for all users, or just one user. The keys are listed in the help for cmd.exe -- I've copied the section to the attached file cmdext.txt. Or we can use a command line switch to turn them on while running this program, ie create a shortcut with a target of cmd /E:On /C [drive:][path][filename of batch file]

    #3 and #4. I've attached my test file (renamed test1.txt) and a troubleshooting file (test2.txt).
    Rename them with .bat extensions, then run test1 as is, using notepad. If it works, substitute your program for notepad.exe and see if it works. If it works with notepad but not your program, put your program name in place of notepad in test2.bat and run that. It will create a file named testoutput.txt (should be in same directory as the batch file). This will show the value of TDDATE before and after your program runs. If it is being changed, we need to pick a different name for TDDATE

    For troubleshooting, you can remove all of the "@" symbols from the start of each line -- this will allow each line to display on the screen as it executes.

    Ok, way past my bedtime, so I hope this all makes sense. Let me know how it goes.

    Jerry
     

    Attached Files:

  5. terryflan

    terryflan Thread Starter

    Joined:
    Aug 7, 2007
    Messages:
    11
    Hi Outcaste

    I run Win XP
    Extensions are SET

    txt1 and txt2 didn't seem to make any difference.
    When I ran TestOutput it still said it didn't like the date.
    When I looked at the Testoutput.txt it showed date as 08/07.
    I removed the :~4 from first line, tried again and BINGO you're a genious.
    Thank you very much.
    Terry
     
  6. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    I can't imagine why you can't read it without opening it, but here it is, have fun. :)
     
  7. terryflan

    terryflan Thread Starter

    Joined:
    Aug 7, 2007
    Messages:
    11
    Sorry John, Not very good at this. Put it down to old age,(75)
    Thanks for the help.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - save current date
  1. montemag
    Replies:
    15
    Views:
    567
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/606293

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice