BATCH script to save DATE to a variable (Users)
> > Many DOS shells already provide this. What particular environment(s) are
> > you targeting?
> I mainly use DOS 7.1 and 6.22 with the standard shell. I use FreeDOS too
> but not for this.
4DOS, DR-DOS COMMAND.COM, and Win7's CMD all have date variables, IIRC.
> There's a freeware diagnostics program, NSSI, that I run on different
> computers while testing them, that is hard coded to print an error message
> if the current date is past 2008.
>
> So with my script I save the current date, set the date as 12-31-2008, run
> the program, and then set the correct date again.
Maybe you need KEEPTIME?
* https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/system/keeptime/
> > KEEPTIME stores system time to time stamp of given file (and creates
> > file if it absent) or restores system time from time stamp of file
> > if file time newer than system time.
That should work simply enough.
> I compiled it and it prints the date this way:
> Sat Mar 01,2025
>
> But it doesn't create the DATE_ variable.
It was just a proof of concept. I was hoping you'd modify it to your needs.
> Could you please tweak your code so that it saves its content to the
> variable DATE_ with the date in this format MM-DD-YYYY? That's the format I
> need to use in my script to set the current date with the DATE command.
Maybe, but I'm not sure you need it.
> Is it possible to create/set a variable (the same way the SET command does)
> with an assembly program? Could you please give an example of assembly code
> that sets this environmental variable FOO=BAR? Just to try to understand it
> better.
Setting the master environment (across all processes and shells) is what is very difficult. I wouldn't recommend that.
Technically, I wouldn't even recommend directly modifying the environment memory, but at program startup, (PSP) ES:2Ch should hold a pointer to the environment data.
(Old Simtel archives have DUMPENV.ZIP to show how to read the local environment.)
The unportable, nonstandard way to set the "local" environment is this:
putenv() (DJGPP)
In short, I don't think it persists after your program ends.
> If you can recommend any reading material on assembly for beginners that'd
> be great.
Randall Hyde's old 16-bit Art of Assembly book may be online somewhere.
But you don't really need assembly here. It was just small and simple enough. Heck, just try this:
echo ? "@set date_=" ; DATE$ : SYSTEM >q.bas
qbasic /run q >q.bat
call q
Complete thread:
- BATCH script to save DATE to a variable - tauro, 01.03.2025, 04:19 (Users)
- BATCH script to save DATE to a variable - Rugxulo, 01.03.2025, 08:14
- BATCH script to save DATE to a variable - ecm, 01.03.2025, 12:15
- BATCH script to save DATE to a variable - marcov, 01.03.2025, 12:45
- BATCH script to save DATE to a variable - tauro, 02.03.2025, 02:16
- BATCH script to save DATE to a variable - Rugxulo, 02.03.2025, 03:26
- BATCH script to save DATE to a variable - RayeR, 25.03.2025, 05:44
- BATCH script to save DATE to a variable - rr, 25.03.2025, 18:41
- BATCH script to save DATE to a variable - Rugxulo, 01.03.2025, 18:43
- BATCH script to save DATE to a variable - rosegondon, 02.03.2025, 17:10
- BATCH script to save DATE to a variable - Rugxulo, 01.03.2025, 08:14