Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DATE command in DOS batch processing

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use the DATE command in DOS batch processing, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

1. System help

C:\ > date /?

Displays or sets the date.

DATE [/ T | date]

Type only DATE without parameters to display the current date setting and prompt

You enter a new date. Press ENTER to keep the original date.

If the command extension is enabled, the DATE command supports the / T command option, which tells the

The command outputs only the current date, but does not prompt for a new date.

2.DATA / T parameter description

This parameter outputs the current date, for example:

C:\ > DATE / T

Monday, 2002-10-28

This date format may be different from that in environment variables, such as

C:\ > echo% DATE%

Monday 2002-10-28

With the for command, you can combine different expressions, such as:

C:\ > for / f "tokens=1,2"% an in ('date/t') do set date=%a

C:\ > set date=2002-10-28

What this statement does is take out the day-of-the-week part of the date/t.

We can get the same result with simpler commands, such as:

C:\ > echo% DATE%

Monday 2002-10-28

C:\ > echo% DATE:~4,10%

2002-10-28

If you want to create a folder or file name with a date in a batch, you can simply do it, such as

C:\ > mkdir% DATE:~4,10%

C:\ > dir 2 *

The volume in drive C is a local disk

The serial number of the volume is 402A-3A7E

Directory of C:\

2002-10-28 19:34 2002-10-28

0 files 0 bytes

1 directory 79282176 available bytes

C:\ > copy mylist mylist%DATE:~4,10%

1 file has been copied.

C:\ > dir my*

The volume in drive C is a local disk

The serial number of the volume is 402A-3A7E

Directory of C:\

2002-09-15 10:00 38 mylist

2002-09-15 10:00 38 mylist2002-10-28

3 files 446 bytes

0 directories 79282176 free bytes

This is useful for some automatic operations in Oracle.

As you can see, through the combination of simple DOS commands, we can do a lot of seemingly complex things, just our thinking.

You can't always get there.

3. About the format of% DATE:~4,10%

The meaning of this command is to take 4-10 middle characters in the output of DATE.

There may be different time formats for different machines, which can be set in the control panel.

You can view the current settings through the ECHO command, such as:

C:\ > echo% DATE%

Monday 2002-10-28

Of course, we can also take the value of the week:

C:\ > echo% DATE:~0,3%

Monday

Of course, you can also come from different directions:

C:\ > echo% DATE:~-10%

2002-10-28

C:\ > echo% DATE:~0,-10%

Monday

Thank you for reading this article carefully. I hope the article "how to use DATE commands in DOS batches" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report