[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2160
  • Last Modified:

How can i Change Date and Time Format VBS

I need to change the format of this

From
9/12/2004 12:25
To
9/12/2004

its actually the last value in the csv file...

So it needs to be something like (strData & "," & strNewDateValue & "," & intPassword)

My script needs to write the data back to another file


strInputData = Split(oInputFile.ReadAll, vbNewline)
On Error Resume Next

For each strData In strInputData
Dim intPassword
Randomize
intPassword = Int(1234567 * Rnd() + 1)
      Set file = objFileSys.CreateTextFile(strExportFile,TRUE)
      file.writeline(strData & "," & intPassword)
Next
file.close
0
dion_p1
Asked:
dion_p1
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The date will always be stored as dd/mm/yyyy hh:mm:ss in the database, but you can always just display the date part using VB code as Format(YourDateValue, "Short Date")

Hope this helps.
-Jim
0
 
jkaiosCommented:
Or you can also use this, which is independent of the "Short Date" setting in Control Panel:

strNewDateValue = Format(theOriginalDateValue, "MM/dd/yyyy")
0
 
ArkCommented:
Use Date function instead of Now
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dion_p1Author Commented:
How can i replace the "/" to "-"

i have

strCDate = Date()
msgbox strCDate

0
 
ia2189Commented:
strCDate = Replace(Date, "/", "-")
msgbox strCDate
0
 
Dany BalianCTOCommented:
here's the syntax

format(originaldatevalue,"MM-dd-yyyy")


you can use any combination you want, the MM part will be replaced by the month, the dd with the days, and the yyyy with the year!

0
 
Dany BalianCTOCommented:
sorry, i didn't notice the vbs part of the question.
ofcourse the format function works only in vb6.

SOLUTIONS:

1- to be able to format date/time in vbs u have to use the formatdatetime which formats the date in 5 fixed formats: general date, long date, short date, long time, short time.
syntax:
FormatDateTime("6/26/1943", p)

p =0 'vbgeneraldate
p=1 'vblongdate
p=2 'vbshortdate
p=3 'vblongtime
p=4 'vbshorttime


2. however, here's a workaround to be able to use the vb's built in format function.

Function Format(vExpression, sFormat)
         set fmt = CreateObject("MSSTDFMT.StdDataFormat")
        fmt.Format = sFormat
 
        set rs = CreateObject("ADODB.Recordset")
        rs.Fields.Append "fldExpression", 12 ' adVariant
 
        rs.Open
        rs.AddNew
 
        set rs("fldExpression").DataFormat = fmt
        rs("fldExpression").Value = vExpression
 
        Format = rs("fldExpression").Value
 
        rs.close: Set rs = Nothing: Set fmt = Nothing
 
End Function

msgbox format(now(),"dd-mm-yyyy")


3. Finally, u can always write your own custom function

dim d
d=now()
msgbox day(d) & "-" & month(d)  & "-" & year(d)


hope this helps,

cheers

dan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now