-2

How to use VBScript to open notepad and paste current date in DDMMYYYY format?

When I use the below code, I get the output in DD/MM/YYYY format. I want it in DDMMYYYY format.

set WshShell = WScript.CreateObject("WScript.Shell")

call WshShell.Run("%windir%\system32\notepad.exe")

Dim aDate

aDate = Date()

WScript.Sleep 4000

WshShell.SendKeys aDate

Could you guys please help me on this one?

Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43
Dishant Parakh
  • 91
  • 1
  • 1
  • 7
  • 2
    Before asking a question, please do at least an small research. – GTAVLover Jul 28 '17 at 04:51
  • 1
    Possible duplicate of [How to use VBScript to open notepad and paste current date in it?](https://stackoverflow.com/questions/45341320/how-to-use-vbscript-to-open-notepad-and-paste-current-date-in-it) – oracle certified professional Jul 28 '17 at 07:17
  • 1
    Possible duplicate of [Format current date and time](https://stackoverflow.com/questions/22574092/format-current-date-and-time) – user692942 Jul 28 '17 at 07:33

1 Answers1

0

The Date format you want: DDMMYYYY (without common slashes)

This should work for you:

Dim WshShell: Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run("%windir%\system32\notepad.exe")
WScript.Sleep 4000

Dim aDate: aDate = WScript.CreateObject("System.Text.StringBuilder").AppendFormat("{0:dd}{0:MM}{0:yyyy}", Now).ToString()

WshShell.SendKeys aDate
GTAVLover
  • 1,407
  • 3
  • 22
  • 41