How can I concatenate date /t, time /t, and an argument in a batch file and append that as one line to a file?

Posted on 2011-03-11
Medium Priority
Last Modified: 2012-06-22
In Windows,

I want a batch file that will append a file with one line that has the date and time on the line, followed by some test, but I want it all on one line.  I pass in an argument that contains the text.

This is what I have now:

rem - Batch file to add a line of text to a daily notes file
date /t >> C:\dailynotes.txt
time /t >> C:\dailynotes.txt
rem - The text is argument 2
echo %1 >> C:\dailynotes.txt

This is the way it looks in my file:
10:55 AM
TRYTHIS 03/11/2011
11:02 AM

How can I get those three items onto one line in the file, not three?
Question by:cashonly
  • 3
  • 2
LVL 33

Assisted Solution

knightEknight earned 1000 total points
ID: 35110438
echo %date% %time% >> C:\dailynotes.txt
LVL 22

Accepted Solution

Christopher McKay earned 1000 total points
ID: 35110444
Have you considered trying something like this:

echo %date%, %time% "stuff" >>c:\dailynotes.txt

Hope this helps!


LVL 33

Expert Comment

ID: 35110471
The following is basically the same thing, but it eliminates the Day-of-Week from the date and the milliseconds from the time:

echo %date:~4% %time:~0,8% >> C:\dailynotes.txt
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 22

Expert Comment

by:Christopher McKay
ID: 35110477
Apparently I type too slow, sorry for duplicating you knightEknight.

Author Closing Comment

ID: 35110481
I'm splitting the points cause while knightEknight was quicker, Bartender_1 was more complete.

TYVM to both!
LVL 33

Expert Comment

ID: 35110489
no worries BT!  Great minds think alike...  and so do ours.  :p

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this tutorial, we’re going to learn how to convert Youtube to mp3 for Free. We'll show you how easy it is to make an mp3 from your video clips so that you can enjoy them offline.
A simple method to resolve a "keyboard not working" problem by modifying the Windows registry. This issue can often be encountered after using the VMware vCenter Converter Standalone Agent to perform a Physical-to-Virtual (P2V) conversion process.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

621 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