Use VBS to get the day before the current date and correct the output format _vbs

Source: Internet
Author: User
Tags current time

Get the current date method one:

Copy Code code as follows:

Currentdate1=date ()
MsgBox Currentdate1

Get the current date method two:

Copy Code code as follows:

Currentdate2=year (now) & "-" &month (now) & "-" &day (now)
MsgBox Currentdate2

Add a: If you want to get a date preceded by a 1-digit front complement 0, such as May 2016 16, if the directory is 2016516 better than 20160516

Copy Code code as follows:

Ystr=year (now)
Mstr=month (now)
If Len (MSTR) <2 then mstr= "0" &mstr
Dstr=day (now)
Dateml=ystr&mstr&dstr
MsgBox (Dateml)

Get the current time:

Copy Code code as follows:

Currenttime=hour (now) & ":" &minute [Now] & ":" &second (now)
m = "Current Time" & CurrentTime
MsgBox m

Use VBS under Windows to take the day before the current date and correct the output format

My_date1 = DATEADD ("D", -1,date)

Action: Take the day before the current time (the current time is 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)

Function: Regardless of the time format set by the system (default is YYYY/M/D), modify the output time format as YYYY-MM-DD, and assign the result to the variable My_date2

Time to view output:

MsgBox my_date1
MsgBox My_date2

The above script is tested by WINDOWS2003, 2008

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.