In VBScript format, the month and date are two digits.

Source: Internet
Author: User

Today, I want to change a function to generate an ID in the form of yyyymmdd. However, the date format generated in VBScript may be in the form of yyyymd, that is, the value 0 in the high position is removed, I found the date and time functions of VBScript, but I didn't find any suitable functions.

I have done something similar before, probably to judge whether the number is smaller than 10, and then append the leading 0. (Just readAlgorithmBy the way, we can also write a pseudoCode: P)

 

// Date () Is the function for obtaining the current date. The default format is yyyy-mm-dd mm and DD, which may have only one digit.

// Year (), month (), and day () are numbers that are extracted from the date.

// Strid is the expected result.

Strid = year (date () & formatstr (month (date () & formatstr (Day (date ()))

Formatstr (m)

// M is the number to be formatted

If CINT (m) <10

M = 0 & CINT (m)

Return m

Haha, This is the pseudo code of an algorithm.

In this way, we can directly extract ten digits and one digit, and then combine them.

Pseudocode:

Formatchar (m)

M = fix (M/10) & (m-fix (M/10) * 10)

Return m

In fact, it's almost the same, but the following can be written in a row without writing a function.

Strid = year (date () & fix (month (date ()/10) & (month (date ()-fix (month (date ()) /10) * 10) & fix (Day (date ()/10) & (Day (date ()-fix (Day (date ()/10) * 10)

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.