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)