?
Solved

What would be the quickest way to Format "Mar 24 2005"  =>  "03/24/2005"

Posted on 2005-03-25
9
Medium Priority
?
131 Views
Last Modified: 2010-05-02
Thanks
0
Comment
Question by:AlexF777
[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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 1000 total points
ID: 13633080
MsgBox Format(CDate("Mar 24 2005"), "mm/dd/yyyy")
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 13633110
to be quicker ;-)

Format("Mar 24 2005", "mm/dd/yyyy")
0
 
LVL 19

Expert Comment

by:Shauli
ID: 13633265
MsgBox CDate("Mar 24 2005")

S
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:cjard
ID: 13635798
define quick:

time it takes to type
time it takes the CPU to do

?
0
 
LVL 6

Expert Comment

by:cjard
ID: 13635809
Option Explicit

Private Sub Form_Load()
  Dim start As Double
  Dim iter As Long
  Dim s As String
 
  start = DateTime.Timer
  For iter = 1 To 100000
    s = CDate("24 Mar 2004")
  Next iter
  Debug.Print "CDATE method took " & DateTime.Timer - start & " sec"
 
  start = DateTime.Timer
  For iter = 1 To 100000
    s = Format("24 Mar 2004", "mm/dd/yyyy")
  Next iter
  Debug.Print "FORMAT method took " & DateTime.Timer - start & " sec"
 
  start = DateTime.Timer
  For iter = 1 To 100000
    s = Format(CDate("Mar 24 2005"), "mm/dd/yyyy")
  Next iter
  Debug.Print "FORMATCDATE method took " & DateTime.Timer - start & " sec"
 
  start = DateTime.Timer
  For iter = 1 To 100000
    s = Format("24 Mar 2004", "mm/dd/yyyy")
  Next iter
  Debug.Print "FORMAT$ method took " & DateTime.Timer - start & " sec"
 
End Sub



my laptop's results are:
CDATE method took 0.657281250001688 sec
FORMAT method took 0.797156250002445 sec
FORMATCDATE method took 0.703281249996508 sec
FORMAT$ method took 0.797156250002445 sec


about 3 seconds to convert 400,000 dates... i think youll have other issues in your data prep than this
0
 
LVL 6

Expert Comment

by:cjard
ID: 13635812
ps, i made an error, not putting Format$ on the last bit of code, only the string printout.. but it makes no difference, infact my Format$ took longer
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13636018
Agreed that any of the above works well enough with the exception of:
s = CDate("24 Mar 2004")

Without using the Format function, the returned format will be the system default short date format.  This may not be in the form "mm/dd/yyyy"
0
 
LVL 19

Expert Comment

by:Shauli
ID: 13636144
<<< This may not be in the form "mm/dd/yyyy">>>
That is true of course, if the locale is not in the format of "mm/dd/yyyy". However, if the locale IS in that format, then this would be the fastest way.

S
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 13636493
assuming the locale having a format of mm/dd/yyyy would, i believe, be a big assumption. why would you want to convert dates from one format to another then?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses

770 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