Doscommand-date command usage

Source: Internet
Author: User
Tags echo command

Date command usage

1. System Help
C:> date /?
Display or set a date.

Date [/T | date]

Enter only date without adding a parameter. The current date setting is displayed and a prompt is displayed.
Enter a new date. Press enter to maintain the original date.

If the command extension is enabled, the date command supports the/T Command Option.
Command output only the current date, but do not prompt output new date.

2. Data/t parameter description

This parameter outputs the current date, for example:

C:> date/T
Monday

The date format may be different from the date format in the environment variable, as shown in figure

C:> echo % date %
Monday 2002-10-28

Different expressions can be combined using the for command, for example:

C:> for/F "tokens = 1, 2" % A in ('date/t') do set date = %

C:> set date = 2002-10-28
In this statement, the week-free part is extracted from date/t.

We can use a simpler command to get the same result, for example:

C:> echo % date %
Monday 2002-10-28

C:> echo % Date :~ 4,10%
2002-10-28

If you want to create folders or file names by date in batch processing, you can simply do this, as shown in figure

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.

C: Directory

<Dir> 2002-10-28
0 files, 0 bytes
1 directory, 79,282,176 available bytes

C:> copy 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.

C: Directory

38 mylist
Mylist2002-10-28
3 files in 446 bytes
0 directories, 79,282,176 available bytes

This is useful for some automatic Oracle operations.

We can see that through the combination of simple doscommands, we can do a lot of seemingly complex things, just our thinking

Not always there.

3. About % Date :~ % Format

This command is used to take 4-10 characters in the date output.
Different machines may have different time formats, which can be set in the control panel.
You can run the echo command to view the current settings, for example:

C:> echo % date %
Monday 2002-10-28

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

C:> echo % Date :~ 0, 3%
Monday

Of course, it can also be different from the following:

C:> echo % Date :~ -10%
2002-10-28

C:> echo % Date :~ 0,-10%.
Monday

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.