Use VBS to get the previous day of the current date and correct the output format

Source: Internet
Author: User
This article mainly introduces how to use VBS to get the previous day of the current date and correct the output format. For more information about how to obtain the current date, see method 1:

Currentdate1=date()msgbox Currentdate1

Method 2:

Currentdate2=year(Now)&"-"&Month(Now)&"-"&day(Now)msgbox Currentdate2

Add one: if you want to get a date that is preceded by one-digit prefix with 0, for example, 2016516, it would be better if the directory is 20160516

ystr=year(Now)mstr=Month(Now)if len(mstr)<2 then mstr="0"&mstrdstr=day(Now)dateml=ystr&mstr&dstrmsgbox(dateml)

Get current time:

CurrentTime = Hour (Now) & ":" & Minute (Now) & ":" & Second (Now) m = "Current Time" & CurrentTime msgbox m

In windows, use VBS to retrieve the previous day of the current date and correct the output format.

My_date1 = DateAdd ("d",-1, date)

Purpose: Take the previous day of the current time (the current time is subject to the system time) and assign the result to the variable my_date1
My_date2 = DatePart ("yyyy", my_date1) & "-" & Right ("0" & DatePart ("m", my_date1), 2) & "-" & Right ("0" & DatePart ("d", my_date1), 2)

Purpose: Modify the output time format to YYYY-MM-DD without considering the system-set time format (default: YYYY/M/D) and assign the result to the variable my_date2

View the Output Time:

Msgbox my_date1
Msgbox my_date2

The above scripts are successfully tested in Windows 2008 and.

For more information about how to use VBS to get the previous day of the current date and correct the output format, see PHP!

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.