How do I get the Date & Time (VBS)

前端 未结 7 1992
臣服心动
臣服心动 2020-12-24 09:11

How do I get the current date and time using VBS (for Windows. I\'m not looking for VBScript for ASP/ASPX or webpages).

7条回答
  •  暖寄归人
    2020-12-24 09:22

    This is an old question but alot of the answers in here use VB or VBA. The tag says vbscript (which is how I got here).

    The answers here got kind of muddled since VB is super broad where you can have so many applications of it. My answer is solely on vbscript and accomplishes my case of formatting in YYYYMMDD in vbscript

    Sharing what I've learned:

    1. There are all the DateTime functions in vbscript defined here so you can mix-n-match to get the result that you want
    2. What I needed was to get the current date and format it in YYYYMMDD to do that I just needed to concat DatePart like so for the current Date: date = DatePart("yyyy",Date) & DatePart("m",Date) & DatePart("d",Date)

    That's all, I hope this helps someone.

提交回复
热议问题