Batch file for one current date in text file

 Robert -
I need a batch file to get the current date and time of my computer and put it in a text file every time I run it.But I need the most current date&time to replace the previous within the same text file, so that my file can have only one record, even if I run it multiple times.
I found this code:
echo %date% %time% >> log.txt

But this one just adds the next date under the previous one.
Your help would be greatly appreciated. Thanks in advance!

10 replies


Remove one of the '>' and you have solved it.

It should look like this:
echo %date% %time% > log.txt

:) Ola
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2821 users have said thank you to us this month


how do I write a script to find system date in the following format YYYYMMDD and use it to create folder using the same date.
these are some simple string manipulations to get Date, Time, and DOW if you would rather not use a FOR

REM - Create Date and Time strings
set Today=%date:~10,4%%date:~4,2%%date:~7,2%
set Now=%time:~0,2%%time:~3,2%%time:~6,2%
set DOW=%date:~0,3%
create one log.txt file on your c:\drive
say log.txt
and create one bat file ,open in edit mode and write the below line of code

echo the current date and tine is %time%%date%>>log.txt
> abdullah
I need program or procedure to extract the Gregorian date and the equevelent Hijri date from windows to the text file for 10 years .
waiting for your response .
To Rename Any File With Date And Time Padded

set dd = %date% %Time%

Ren File_To_Rename.txt MyFile__%dd:~0,2%_%dd:~3,2%_%dd:~6,4%___%dd:~11,2%_%dd:~14,2%.txt

1) To clarify: The rename command is issued as a single line
2) The variable positions are not correct for English language WinXP but close enough to figure out what they should be.
Otherwise, great tip!!!
Your line does an apend:
echo %date% %time% >> log.txt

The following line wil overwrite the existing file:
echo %date% %time% > log.txt
this works well... removes "/"

FOR %%A IN (%Date:/=%) DO SET Today=%%A
ren test.txt "test "%TODAY%.txt
Registration date
Saturday November 7, 2009
Last seen
July 18, 2012
Is this a POS application ? I think you are looking for a file that's for yesterday - so if today is 02/24, you are looking for file name with "0223". Is it correct ?

Anyway, here is a biterscripting script.

# Script CheckYesterday.txt
var str file, date
# Get yesterday's date.
set $date = addtime(diff("-1000000"))
# Get only the mmdd part.
chex "8[" $date > null ; chex "4]" $date > null
# The file name will be "C:/somefolder/TRB0"+$date+".zip"
set $file = "C:/somefolder/TRB0"+$date+".zip"
# Check if file exists.
af $file
if ($fexists)
    echo "File " $file " exists."
    echo "File " $file " does not exist."

Copy and paste this script into file "C:/Scripts/CheckYesterday.txt", change "C:/somefolder" to the coorect folder path, then execute this command in biterscripting each morning.

script "C:/Scripts/CheckYesterday.txt"
Registration date
Saturday November 7, 2009
Last seen
July 18, 2012
You can use the gettime() function in bierscripting to get the current date and time and rename files using that. For example, the following script will rename all files in folder "C:/folder" by appending a timestamp to file names.

# Script AppendTimestamp.txt
var str folder, list, file, extn, name
lf -n "*" $folder ($ftype=="f") > $list
while ($list <> "")
    lex "1" $list > $file ; stex -p "^/^l[" $file > $name ; stex "[^.^l" $name > $extn
    system rename ("\""+$file+"\"") ("\""+$name+"_"+gettime()+$extn+"\"")

To run the script, copy and paste the script into file C:/Scripts/AppendTimestamp.txt, then enter the following command in biterscripting

script "C:/Scripts/AppendTimestamp.txt" folder("C:/somefolder")

It will rename all files in folder "C:/somefolder" accordingly.
I am needing to create a batch file the will display a message on the screen each morning and let me know a certain file was created each night at my "day end"

Each night when my store closes, I have a file that is created and zipped up to a certain directory with the name

I have created a batch file to screen pop notepad and give me a message with the current date that the file exist.
But what I dont know how to do is put in the "if exits" statement based the "modified" date of the file.

Can someone help me?

Use this instead:

echo %date% %time% > log.txt

>> appends to a file.
> overwrites a file. Use with caution.

Protip: Use a unix system like FreeBSD and save yourself a lot of grief.
Guys can anyone help me to build a batch file that will captured the date and time and will output as the title in .txt format. and will recreate another text file any time I ran the batch file.

Example output:

072810_0528H.txt - first run batch file
072810_0529H.txt - second run of batch file

your help is much appreciated.
Thanks in advance
You can use this..
REM mmddyyyy, just switch it around if you want the yyyy to be the first
For /F "tokens=2-4 delims=/ " %%a in ("%DATE%") DO SET MDY=%%a%%b%%c
REM hhdd, if you need the secs you can add the 3rd token
FOR /F "tokens=1,2 delims=:" %%d in ("%TIME%") DO SET ORAS=%%d%%e

REM then just output it to a file each time
echo > %MDY%.%ORAS%
REM or you can run a command and output it and add an ext.
whatever cmd > %MDY%.%ORAS%.TXT
mdrdy thank's for the script it works...

much appreciated your help..
this code will tell it to delete the old one and replace it:
del log.txt
echo %date% %time% >> log.txt

basically add the del log.txt first so it will delete it and then afterwards create it again hop this help
This is the code to display current date and time, tab delimited:

@echo off
echo/|set /p =%date% >datetimelog.txt

@echo off & setlocal EnableDelayedExpansion
set TAB=
set SPACE=
for /f "delims=" %%i in (datetimelog.txt) do (
set row=
set count=0
for %%j in (%%i) do (
set /A count=!count!+1
set char=%TAB%
if !count!==3 set char=%SPACE%
set row=!row!%%j!char!
set row=!row:~0,-1!
echo.!row! > datetimelog.txt

It will display something like this :

04/06/2010 03:41 PM

Hope this helps someone else too! Thanks!
put just one >, that will overwrite the file putting two >> will APPEND to the existing file.
Here's your long awaited answer...

echo %time% %date%>text.txt

note: use only one ">" in the command line so it will erase the previous txt file and replace it with the text you want.
I was wondering if you gurus can give me some direction...

I run a Specials Menu at a restaurant using powerpoint. There are two specials files (lunch.pps and dinner.pps)
When this system reboots, I want a batch file to determine which powerpoint file to open based on what time it is.

For instance, if it's anywhere between 11am and 3pm, open the lunch file. If its any other time, run the dinner.pps file. Make sense?

Does anyone know what the syntax is to do this?
> rblanda
for /f "tokens=1-2 delims=: " %%a in ('time /T') do set hour=%%a
if %hour% gtr 15 goto xxx

The above will check the hour is e.g. 3pm