# (unresolved) date prob



## techi (Dec 10, 2003)

ok first off, hi

i know there are things on your forum about this but all of them leave me in the dark, im a complete beginner, iv never done dos b4 so i dont understand a thing really.

im running win2k server
i have xp and 2000 machines logging in
they run the following batch file at login:



> echo %username% %computername% %date% time%>>\\Srv2K\LoginLog$\Users.txt


writes to Users.txt on shared area:-



> Administrator SRV2K Mon 08/12/2003 22:11:53.72
> Administrator SRV2K Mon 08/12/2003 22:21:20.71
> Administrator SRV2K Mon 08/12/2003 22:24:53.43
> trial TECHI-BUILD Mon 12/08/2003 22:46:27.13
> Administrator SRV2K Wed 10/12/2003 21:27:25.20


this is to store who was last logged into a machine (and is deliberately crashing them, to a hdd failure), time and date are important in the file text.

i want to be able to store the file name as day.txt (Mon.txt, Tue.txt or 0.txt, 1.txt)

i have tried lots of examples, and would prefer it if there were NO temp.bat files used.

as this is to be used in a school environment speed is also a key issue, as the large .bat files the previous technician writ are being closed on execution, then lil brats are phoning me up asking why their network drive isnt working.


----------



## techi (Dec 10, 2003)

ok i got a little closer



> set filename=%date%
> echo %username% %computername% %time%>>\\Srv2K\LoginLog$\%filename%.txt
> pause


this does what i want but stores files as just the day with no extentions (e.g. Mon)

it still houses the correct information but i need somthing to the effect of:-

%date% + %.txt%

as you can see im not used to dos programming (or command prompt programming for those who dont think the two are part of one)


----------



## mbechard (Nov 11, 2003)

If there is a domain controller, there is a simpler way to do this. I have some notes that I used a couple times. This sets the domain controler as a time server that is synched with a military time server. You don't need to run it as a batch file at every login, its automatic.

Set time on server and domain computers

net time /setsntp:192.5.41.209

net time /DOMAIN:domainname/set

net stop w32time

w32tm -once

net start w32time


----------



## mbechard (Nov 11, 2003)

never mind - I read your problem..


----------



## techi (Dec 10, 2003)

ok - thx for trying though


----------



## techi (Dec 10, 2003)

actualy cant somthing be done like a file is kept with a referance number in as the date, the current date is checked to this, the filename is the differance in days between the two dates?

so in the file is kept "15/12/2003"
current date is "20/12/2003"
filename is "5.txt"

therefore a fresh log is always kept

thinking aloud: why use a file, why not hard code the check date the day the batch file is issued



> set check=Mon 15/12/2003
> set today=%date%
> filename=today-check
> echo %username% %computername% %time%>>\\Srv2K\LoginLog$\%filename%.txt
> pause


common i only need help with code the brain is working well


----------



## Jedi_Master (Mar 13, 2002)

Howdy techi...

I've tested this in XP locally, should work in W2K also...

_____________________________________________________

set filename=%date%
echo %username% %computername% %date% %time% >> c:\%filename%

@echo off
cls
if exist c:\sun goto sun
if exist c:\mon goto mon
if exist c:\tue goto tue
if exist c:\wed goto wed
if exist c:\thu goto thu
if exist c:\fri goto fri
if exist c:\sat goto sat

:sun
ren c:\sun sun.txt 
copy c:\sun.txt/a+c:\sun/b
del c:\sun
goto end

:mon
ren c:\mon mon.txt
copy c:\mon.txt/a+c:\mon/b
del c:\mon
goto end

:tue
ren c:\tue tue.txt
copy c:\tue.txt/a+c:\tue/b
del c:\tue
goto end

:wed
ren c:\wed wed.txt
copy c:\wed.txt/a+c:\wed/b
del c:\wed
goto end

:thu
ren c:\thu thu.txt
copy c:\thu.txt/a+c:\thu/b
del c:\thu
goto end

:fri
ren c:\fri fri.txt 
copy c:\fri.txt/a+c:\fri/b
del c:\fri
goto end

:sat
ren c:\sat sat.txt
copy c:\sat.txt/a+c:\sat/b
del c:\sat
goto end

:end

______________________________________________________

Haven't tested from a network, just change everywhere it says 
*c:\* to where the network share is...


----------



## techi (Dec 10, 2003)

ty, i will try this later, its late now.


----------



## Jedi_Master (Mar 13, 2002)

Hey techi I edited my post, forgot to add the *goto end* statement ( the old one will still work, this way may be a tad faster )...


----------



## techi (Dec 10, 2003)

i put pause at the end for testin purposes,

The system cannot find the file specified.
The system cannot find the file specified.
Could Not Find c:\sun
Press any key to continue . . .



will i have to create the file initialy manualy to get it started?


----------



## Jedi_Master (Mar 13, 2002)

No you don't have to create the file, it can't find it because it isn't sunday yet...


----------



## smontejo (Aug 17, 2003)

I'm sorry but I dont understand the whole problem. Isn't

set file=%date%.txt

enough?


----------



## techi (Dec 10, 2003)

no that does this:-

Batch start----------

echo %username% %computername% %time%>>\\Srv2K\LoginLog$\%date%.txt

------------Batch end

log start------------

Administrator SRV2K 22:11:53.72 08/12/2003
Administrator SRV2K 22:21:20.71 08/12/2003
Administrator SRV2K 22:24:53.43 08/12/2003

-------------log end

in a file called Mon with no extention

note the date at the end of the log sentance even though its not asked to in the batch file.


----------



## Jedi_Master (Mar 13, 2002)

Actually that is coming from %time%


----------



## zephyr (Nov 6, 2003)

I don't know if this will answer your needs since it's not exactly what you want. What it will do is generate the file named login.txt which will contain the user name, computer name, time, and date. That file will then be copied to a folder that is named for the day of the week.

It's path looks like this as I used it:
C:\Documents and Settings\Owner\Desktop\SAT\login.txt

and the contents look like this:
Owner DON 23:10:50.42 Sat 12/13/2003
Owner DON 23:14:27.82 Sat 12/13/2003 
Owner DON 23:15:15.07 Sat 12/13/2003 
Owner DON 23:19:02.93 Sat 12/13/2003

It will require you to get the XXCOPY.EXE command which is a freeware utility. Although it is free, the particular switch being used to generate the day of the week is intended for corporate use and if you do not register the software, it will pause the batch and inform you how to prevent that pause. It will go ahead and run when you hit "Any Key" so it'll still function, just have that little nag.

Here's the code for what I have named login.bat

```
echo %username% %computername% %time% %date% >>"C:\Documents and Settings\Owner\Desktop\login.txt"
xxcopy /yy  "C:\Documents and Settings\Owner\Desktop\login.txt" "C:\Documents and Settings\Owner\Desktop\/$WWW$\"
```
You can learn more about XXCOPY and you'll appreciate its power in time (pun intended).

I think this actually accomplishes what you need since a new folder will be generated every day of the week. It will eventually write over the folders, so if you need to archive them, do so before the eighth day begins to preserve them. At that same time, you would want to delete the first login.txt file so as not to keep appending it forever. It will be recreated with the first run thereafter.

If all that maintenance is too much of a drag, I can add a couple more switches that will name the folder with the year and date, along with the day of the week. That would make it perpetual, without need to manually archive. The switch string would then look like this: /$YYYY-MM-DD-WWW$\ and the folder would be named like this: 2003-12-13-SAT. Great stuff, what?

Regards, Don.


----------



## techi (Dec 10, 2003)

ill try this tomorrow, thx


----------



## Jedi_Master (Mar 13, 2002)

So I take it the one I wrote didn't work ??


----------



## techi (Dec 10, 2003)

Jedi:

yes i got this:-

A duplicate file name exists, or the file
cannot be found.
c:\sun.txt
c:\Sun
1 file(s) copied.
Press any key to continue . . .

but it did do what it was supposed to.

i will test it tomorrow to see what happens once the day has changed, thx already though, needs testing for speed over a network too.


----------



## Jedi_Master (Mar 13, 2002)

Ok...just wandering...



> A duplicate file name exists, or the file
> cannot be found.


Yea...I tried using errorlevels to avoid this, but for some reason it didn't work the way I wanted it to...

This line is causing it *ren c:\xxx xxx.txt * ( where xxx is the day ) but it was the only wat I could find to add a .txt extension to the Sun file that was created...

Also may want to take out %date% from echo %username% %computername% %date% %time% >> c:\%filename%, to avoid adding a second date to the .txt file...


----------



## Jedi_Master (Mar 13, 2002)

Give this one a shot it will get rid of the error...

__________________________________________________________________________

set filename=%date%
echo %username% %computername% %time% >> c:\%filename%

@echo off
cls
if exist c:\sun goto sun
if exist c:\mon goto mon
if exist c:\tue goto tue
if exist c:\wed goto wed
if exist c:\thu goto thu
if exist c:\fri goto fri
if exist c:\sat goto sat

:sun
if exist c:\sun.txt goto sun1
ren c:\sun sun.txt 

:sun1 
copy c:\sun.txt/a+c:\sun/b
del c:\sun
goto end

:mon
if exist c:\mon.txt goto mon1
ren c:\mon mon.txt

:mon1
copy c:\mon.txt/a+c:\mon/b
del c:\mon
goto end

:tue
if exist c:\tue.txt goto tue1
ren c:\tue tue.txt

:tue1 
copy c:\tue.txt/a+c:\tue/b
del c:\tue
goto end

:wed
if exist c:\wed.txt goto wed1
ren c:\wed wed.txt

:wed1 
copy c:\wed.txt/a+c:\wed/b
del c:\wed
goto end

:thu
if exist c:\thu.txt goto thu1
ren c:\thu thu.txt

:thu1 
copy c:\thu.txt/a+c:\thu/b
del c:\thu
goto end

:fri
if exist c:\fri.txt goto fri1
ren c:\fri fri.txt

:fri1 
copy c:\fri.txt/a+c:\fri/b
del c:\fri
goto end

:sat
if exist c:\sat.txt goto sat1
ren c:\sat sat.txt

:sat1
copy c:\sat.txt/a+c:\sat/b
del c:\sat
goto end

:end
_____________________________________________________________________________


----------



## techi (Dec 10, 2003)

i tried this on one of the laptops and it appears to look like it might work, i will retest at home in a safe environment.

i did come accross a possible problem though.

not all machines in the network use the Mon part of date so it cant find the file to rename it.

by changing the date seperator to a "-" the following then worked under xp:-


```
echo %username% %computername% %time% >> c:\%date%.txt
pause
```
i dont think this will through 2000 though.

i realy now need to find a way of setting the date format to "Mon 15-12-2003" without using windows - because windows dosnt appear to have a setting available to allow you to put the day reference in front of the number date.


----------



## techi (Dec 10, 2003)

BTW i added this to give a little better error msg:


```
set filename=%date%
echo %username% %computername% %time% >> c:\%filename%

@echo off
cls
if exist c:\sun goto sun
if exist c:\mon goto mon
if exist c:\tue goto tue
if exist c:\wed goto wed
if exist c:\thu goto thu
if exist c:\fri goto fri
if exist c:\sat goto sat
goto err1

:sun
if exist c:\sun.txt goto sun1
ren c:\sun sun.txt 

:sun1 
copy c:\sun.txt/a+c:\sun/b
del c:\sun
goto end

:mon
if exist c:\mon.txt goto mon1
ren c:\mon mon.txt

:mon1
copy c:\mon.txt/a+c:\mon/b
del c:\mon
goto end

:tue
if exist c:\tue.txt goto tue1
ren c:\tue tue.txt

:tue1 
copy c:\tue.txt/a+c:\tue/b
del c:\tue
goto end

:wed
if exist c:\wed.txt goto wed1
ren c:\wed wed.txt

:wed1 
copy c:\wed.txt/a+c:\wed/b
del c:\wed
goto end

:thu
if exist c:\thu.txt goto thu1
ren c:\thu thu.txt

:thu1 
copy c:\thu.txt/a+c:\thu/b
del c:\thu
goto end

:fri
if exist c:\fri.txt goto fri1
ren c:\fri fri.txt

:fri1 
copy c:\fri.txt/a+c:\fri/b
del c:\fri
goto end

:sat
if exist c:\sat.txt goto sat1
ren c:\sat sat.txt

:sat1
copy c:\sat.txt/a+c:\sat/b
del c:\sat
goto end

:err1
echo No files are present
goto end

:end
```


----------



## Jedi_Master (Mar 13, 2002)

> not all machines in the network use the Mon part of date so it cant find the file to rename it.


Does that error pop up the next time it is ran ?

I tested it on both W2k and XP...



> i realy now need to find a way of setting the date format to "Mon 15-12-2003"


This may have to be written in C or something else I don't know of a way it can be changed with a batch file, and still have a .txt extension...


----------



## techi (Dec 10, 2003)

you may have misunderstood me a little, sorry.

the change would just have to make the pc reginol date say the Mon part of the date, not do this every time the .bat file is done, this would be loaded once by administrator, not run at login

next time i ran it got error in filename 15/12/2003 cos of "/" thats why i change it to "-" but that was just testing ur code, that worked so if i use pc with mon at front it should work.

just tested it, it did work on my home comps, now to find out how to set the reginal date on any pc to say "Mon 14/12/2003".


----------



## techi (Dec 10, 2003)

close now:-



> rem DONT understand the for loop in dos at all what is %%i - start character, i realised this
> rem the required date output is year\month\day, but this does day\year - got this sorted also
> rem now the problem is that the day isnt being recognised besause there is no / befor the day 16/12/2003
> 
> ...


----------



## techi (Dec 10, 2003)

Hooray tg....



> for /F "tokens=1-4 delims=/- " %%A in ('date/T') do (
> set day=%%A
> set month=%%B
> set year=%%C)
> ...


Ty for your help this is basicaly your one with the days but broken to months and years


----------

