Controling Date format in XP DOS emulator

Discussion in 'Software' started by drapls, Nov 23, 2005.

  1. drapls

    drapls Private E-2

    I am currently using Pentium 4 3.2 GHz running Windows XP Version 5.1 on a government agency network. I don't think any of that is particularly relevant, but if it helps, there it is.

    There is a batch file on my computer that uses the %data% variable. If I change the format in the GUI, it botches up the function of the batch file because it does not match the expectations of the batch programmer. For example, if I change from the sortable yyyy-mm-dd required by the batch file to the international dd-mmm-yyyy that I prefer for other uses, the batch file fails, partly because I have introduced alpha characters and partly because I have scrambled the order.

    I am trying to determine if there is a batch syntax for changing that date format. If so, I can add a line to the batch file changing the format to what the batch needs before it uses it and then change it back before the batch file terminates.

    Thanks for any guidance.
    Kwik DRA
     
  2. theefool

    theefool Geekified

    Welcome to MajorGeeks!

    I wrote a batch file that may help in this case, located within the programming section of the forums.

    I love batch files, been making .bat(ch) scripts since 1996 (Military days). Anyway.....

    http://forums.majorgeeks.com/showthread.php?t=68164

    If this is not what you are wanting, then, please, post in the programming section of this forum. Or continue posting here.

    I'd love to help out!
     
  3. drapls

    drapls Private E-2

    Looks like there is some potential here, but I am missing the point. First, please help me understand what you are doing here, and then I will ask more pointed questions. I have interspersed comments into your batch file.

    @echo off
    Rem :Created by Theefool from MajorGeeks
    Rem :Version 1
    setlocal

    Rem :Create a temp file of the variable date
    echo %date% > test1.txt

    Rem :parse the day word with the actual day/month/year number

    Your REM(ark) is helpful here, but the syntax is not very familiar. I have never found much doc on batch FOR statements that I could make much sense from. I am reading the DOS HELP as I study your file, and I can sort of follow what’s going on. I think this line from my batch file does about the same function as the next 5 lines plus the RENAME command just before the EXIT of your batch. It copies “dailyactivitylog.doc” to “DailyActivityLog2005-11-23_180931.doc”
    copy f:\WORD\diary\dailyactivitylog.doc "f:\WORD\diary\DailyActivityLog%date%_%time%:~0,-9%%time%:~3,-6%%time%:~6,-3%.doc"Is there anything substantially different between the two?
    for /F "tokens=2" %%i in (test1.txt) do echo %%i > test2.txt
    Rem :Get rid of the slashes and set variables
    for /F "tokens=1 delims=/" %%i in (test2.txt) do set month=%%i
    for /F "tokens=2 delims=/" %%i in (test2.txt) do set day=%%i
    for /F "tokens=3 delims=/" %%i in (test2.txt) do set year=%%i


    I do not follow why we are creating this directory nor do I get why we would then copy from it in the next command. It seems it would be empty at that point.
    cd /d c:\ACT
    copy c:\ACT\*.* e:\ACT


    This is part of the creation of the unique filename that includes the date.
    e:
    ren ACT ACT%month%%day%%year%
    exit (typically you do not need to add this)


    This batch seems to do something very similar to what mine does except the format of our date is assumes to include dashes rather than slashes, so we do not need to parse them. The time on the other hand, includes colons and need parsed, so we have done that in the line I showed above. One other minor difference is that my files includes the date and time in the file name while yours is adding it to a folder name.

    However, none of this addressed the core issue as far as I can tell. If someone changes the date format, neither your file nor mine will create the same result and they may not work at all.

    What I am trying to figure out is how, if possible, to change the date format at the top of my file (using syntax) to assure that it is in the correct format for the parsing. In my case, I would actually like to change it back after the date is extracted so that I can have a different format in my other operations. I need it to be in
    yyyymmdd (all numeric)
    for the file names but I would prefer to see
    dd mmm yyyy (International format with alpha month)
    for my general daily operations.

    The basic issue is that I know how to change date formats using the GUI, but I have not found a way to do that using the DOS syntax.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds