Solved

Insert time and date into log file

Posted on 2014-12-10
10
348 Views
Last Modified: 2015-01-22
Hey Experts.  I wanted to insert the time and date into a log file that related to when the script was ran.  A format like:  mm/dd/yy xx:xx pm/am

This would be used in a batch script.  Thanks!
0
Comment
Question by:samiam41
10 Comments
 
LVL 23

Accepted Solution

by:
NVIT earned 167 total points
ID: 40491571
Add this to your .bat file:
echo %date% %time% >> Logfile.txt

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 40491623
This is what I tried but it didn't work

echo ----[Date & Time Stamp]---->> %logfile%
echo %date:~4,2%_%date:~7,2%_%date:~10,4%>> %logfile%
echo %time:~0,2%_%time:~3,2%>> %logfile%
echo. >> %logfile%
0
 
LVL 9

Author Comment

by:samiam41
ID: 40491627
NewVillageIT, thanks for responding.  Here is what I get when I use your script.

The system cannot accept the time entered.
Enter the new time:
0
 

Assisted Solution

by:ISGIT2009
ISGIT2009 earned 166 total points
ID: 40491641
You can use the following to pull out specific parts of the %DATE% and %TIME% variables to get it to a format you want:

So, if the variable %DATE% is equal to "10/12/2014" which is dd/mm/yyy format and %TIME% was 15:49:08.71

In a batch script, you could do the following:

echo DATE: %DATE:~3,2%/%DATE:~0,2%/%DATE:~8,2%
echo TIME: %TIME:~0,2%.%TIME:~3,2%

Open in new window


Would produce:

DATE: 12/10/14
TIME: 15.49

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 40491651
SOB.....  I used [Date & Time Stamp] which caused a problem.  I took the & out and replaced it with "and".  Now it works.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 23

Expert Comment

by:NVIT
ID: 40491652
samiam41,

Try setting DT and TM first. Then replace DATE and TIME with DT and TM in your last post to me:
set dt=%date%
set tm=%time%

Open in new window

0
 
LVL 83

Assisted Solution

by:oBdA
oBdA earned 167 total points
ID: 40491654
Your initial version should work; the issue is with the following line:
echo ----[Date & Time Stamp]---->> %logfile%

Open in new window

The ampersand tells the batch interpreter that a new command follows, so it now tries to run the command "Time" (which then produces the error).
Replace the & either with "and", or escape it with a "^":
echo ----[Date ^& Time Stamp]---->> %logfile%

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 40491689
Thanks for the help and teamwork everyone!
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40492317
samiam41,

I'm glad to have helped.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40564733
Greetings!  If anyone has some spare time and would like to earn some more points, I would appreciate your help.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28601914.html
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now