Solved

How can i Change Date and Time Format VBS

Posted on 2006-11-13
7
2,145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 66

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 28

Expert Comment

by:Ark
ID: 17936957
Use Date function instead of Now
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

707 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