-1

I writing a code in VBScript, but I cannot get the datetime part right.

I'm using FormatDateTime(now), but the gives not the best result like

FormatDateTime(now)

8-01-2016 9:05:12 becomes 01-08-2016 9:05:12.
28-01-2016 19:01:18 stays 28-01-2016 19:01:18.

Has to be:

8-01-2016 9:05:12
28-01-2016 19:01:18

Is there a way to get both the same?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
dave
  • 59
  • 1
  • 7

2 Answers2

0

Try using the format argument of FormatDateTime.

FormatDateTime(now, 2) 'This should return in mm/dd/yy format

More info here.

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
0

http://www.w3schools.com/asp/func_formatdatetime.asp

format (Optional) A value that specifies the date/time format to use Can take the following values:

0 = vbGeneralDate - Default. Returns date: mm/dd/yy and time if specified: hh:mm:ss PM/AM.

1 = vbLongDate - Returns date: weekday, monthname, year

2 = vbShortDate - Returns date: mm/dd/yy

3 = vbLongTime - Returns time: hh:mm:ss PM/AM

4 = vbShortTime - Return time: hh:mm

This should do what you want.

od = "28-01-2016 19:01:18"
nd = FormatDateTime(od,0)
MsgBox(nd)

Output: 1/28/2016 7:01:18 PM