[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How can i Change Date and Time Format VBS

Posted on 2006-11-13
7
Medium Priority
?
2,155 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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