> I just can't figure this one out: From a .bat file, I want to write > entries to a log file. Each entry should have a date and time in the > form YYYYMMDD:HHMMSS I have searched the internet for solutions on > how to do this, but none of the solutions work (I think they are for > cmd.exe in modern Windows which is more advanced than command.com).
You're correct. Most of the time these days if you search for some kind of "DOS Batch" solution to a problem on the web they assume "DOS" and Windows command prompt (NTVDM) are the same thing. They aren't. You're not going to be able to do this straight from DOS prompt itself. You'll need some help from some external utilities. > My first problem is, that I just cannot figure out how to write just > the date without all the preceeding text (Current date is Thu > 12-23-2022). You really can't manipulate the way the date and time are formatted with the DATE and TIME command, at least not very much. The output of the DATE and TIME command should comply with the current COUNTRY (locale) settings you have DOS set up for. E.g., some COUNTRY settings will output the date as 12-23-2022 while others will output 2022-23-12. You probably don't want to mess with your COUNTRY settings, though, since that will change how a lot of other things appear in DOS also. > I tried some a substring routine like this, which I found on a web > page > > set YYYYMMDD=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% > echo %YYYYMMDD% > > I changed the numbers to reflect my date output That's an NTVDM (CMD) thing. It won't work in "real" DOS. > I ran the .bat file, but all it says i "ECHO is on", so first problem > is: How do I write a date to a file from a .bat file? What you need to do is redirect the output of the DATE command to a file: DATE > Date.Txt This will create a file called Date.Txt and it will contain what the DATE command normally send to the screen. You could then follow it up by appending the time to the same file: TIME >> Date.Txt Note that this one needs two arrows ">>" to append to the end of the file. If you just do one arrow it will overwrite the file instead of appending to it. You could then manipulate the Date.Txt file with a macro in a text editor or something like that. I would probably use a DOS port of the Unix utility called SED. SED is a good way to manipulate text files automatically, but it can be a little tricky to use. > Second problem is, that I want to alway have the date formatted as > YYYYMMDD no matter which locale it is run on. Is there any call that > can be made in FreeDOS to automatically format the date in a specifc > way no matter which locale is used? That's another level of complication. Even the above solution of redirecting the DATE and TIME outputs will be Locale-dependent, so manipulating things with SED will get really complicated. If this were me what I would do is create a custom utility. I actually have a utility I call DATES, but I've never officially released it. The output of DATES looks like this: DATES 1.00, (C) 2022, Bret Johnson. DATE TIME mm-dd-yyyy hh:mm:ss.dd ---------- ------------ BIOS: 12-23-2022 07:53:54.21a CMOS: 12-23-2022 07:53:55.00a The main reason I wrote DATES was to be able to see the difference between the BIOS clock (which is what DOS uses) and the CMOS clock (which is the one that the computer uses to initialize the time when you first boot up). The format of the date and time outputs are locale-specific, though, so the output will not always be mm-dd-yy for the date. What I would suggest is that you take the source code for DATES (it is written for NASM which you can get for free) and manipulate it so it gives you the output you desire. I'll send you the source code for DATES if you want it. _______________________________________________ Freedos-user mailing list Freedos-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freedos-user