Computing.Net > Forums > Programming > TIME /T Command?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

TIME /T Command?

Reply to Message Icon

Name: Carts
Date: September 30, 2008 at 18:33:21 Pacific
OS: WinXP
CPU/Ram: AMD Athlon XP 3200+
Product: eMachines
Comment:

I'm making a messaging batch, and I would like to add a timestamp to the messages sent. I know how to make it show on-screen but how can I get the batch to echo it to a text? All it echoes is 'TIME /T'. Kind of basic I'm sure, but...

I'm using delayed expansion if that makes any difference.

Babaloomba



Sponsored Link
Ads by Google

Response Number 1
Name: Valerie (by Garibaldi)
Date: September 30, 2008 at 20:11:14 Pacific
Reply:

Use the %time% environment variable.

echo %time% >> path\filename

You can change the output to suit your format.


0

Response Number 2
Name: Judago
Date: October 1, 2008 at 00:36:45 Pacific
Reply:

I tend to use time /t in a for loop, especially if the time is to be displayed, because it *usually* outputs 12hr with am/pm at the end. Generally I find this easier to read, of course this is just a preference and to each his own.


for /f "delims=" %%g in ('time /t') do set 12hrtm=%%g
echo %12hrtm%

This may have different results depending on your settings.


0

Response Number 3
Name: Carts
Date: October 1, 2008 at 15:30:13 Pacific
Reply:

None of this is working. All I need to know is what syntax to put 'time /t' in to make the batch echo the actual time instead of 'time /t'.

Babaloomba


0

Response Number 4
Name: Mechanix2Go
Date: October 1, 2008 at 16:00:11 Pacific
Reply:

echo %time%


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: Judago
Date: October 2, 2008 at 00:34:12 Pacific
Reply:

Sorry variables starting with numbers in batch file...


FOR /F "DELIMS=" %%G IN ('TIME /T') DO SET HRTIME=%%G
ECHO %HRTIME%

I tested the command in the my last post on the command line, and forgot about variables starting with numbers not being allowed because of the conflict with arguments.


0

Related Posts

See More



Response Number 6
Name: Carts
Date: October 2, 2008 at 18:13:37 Pacific
Reply:

I guess I wasn't clear.

I need the "time /t" command to be written into a .txt file. Not the %time% command, but time /t.

I figured out how to do it by myself today by writing;

time /t >> blah.txt

...but,

I'd like it to be in the same line as;

echo (!user!): !message! >> blah.txt

I want it to be;

echo #time# (!user!): !message! >> blah.txt

I've tried;

echo time /t (!user!): !message! >> blah.txt
echo %time% (!user!): !message! >> blah.txt
echo %time% /t (!user!): !message! >> blah.txt
echo %time /t% (!user!): !message! >> blah.txt
echo !time /t! (!user!): !message! >> blah.txt
echo !time! /t (!user!): !message! >> blah.txt

%time% works, but gives military time with milliseconds.

So...

Babaloomba


0

Response Number 7
Name: Judago
Date: October 3, 2008 at 01:32:28 Pacific
Reply:


FOR /F "DELIMS=" %%G IN ('TIME /T') DO ECHO %%G (!USER!): !MESSAGE!>>BLAH.TXT


0

Response Number 8
Name: lee123abc
Date: October 3, 2008 at 03:43:27 Pacific
Reply:

is this too simple? It does work! Hope it helps
:: thanks to IVO and Mech2 for assistance
@echo off
cls
set message=
set /p message=
echo %time:~0,8% (%username%): %message% > c:\temp_msg.txt
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%A in (c:\temp_msg.txt) do (
set line=%%A
echo.!line!>> c:\msg_history.log)
::rem the next line if you dont want the history to pop up, i enabled it just to show you it works.
start c:\msg_history.log
del c:\temp_msg.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: TIME /T Command?

Batch File-12 hours time format www.computing.net/answers/programming/batch-file12-hours-time-format/16748.html

Monitor Log file useing DOC BATCH www.computing.net/answers/programming/monitor-log-file-useing-doc-batch-/16455.html

Escape Command www.computing.net/answers/programming/escape-command/16052.html