Solved

How can i Change Date and Time Format VBS

Posted on 2006-11-13
7
2,134 Views
Last Modified: 2007-11-27
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
Comment
Question by:dion_p1
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17935596
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
 
LVL 12

Expert Comment

by:jkaios
ID: 17935648
Or you can also use this, which is independent of the "Short Date" setting in Control Panel:

strNewDateValue = Format(theOriginalDateValue, "MM/dd/yyyy")
0
 
LVL 27

Expert Comment

by:Ark
ID: 17936957
Use Date function instead of Now
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:dion_p1
ID: 17937132
How can i replace the "/" to "-"

i have

strCDate = Date()
msgbox strCDate

0
 
LVL 3

Expert Comment

by:ia2189
ID: 17938129
strCDate = Replace(Date, "/", "-")
msgbox strCDate
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 17941039
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
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 17941189
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now