Solved

Breaking down a date

Posted on 2001-09-17
4
153 Views
Last Modified: 2010-05-02
I have a program that asks a user for a date.  I take the input and make sure it's valid and then I convert it using CDate into the MM/DD/YYYY format.

However, the system I am writing this program for requires the date to be in the MMDDYY format.  How can I cut out the proper fields from the MM/DD/YYYY to get it into the MMDDYY format?
0
Comment
Question by:ahelgeson
4 Comments
 
LVL 1

Accepted Solution

by:
ripnasty earned 100 total points
ID: 6488335
Use the Format function

strDate = Format (yourdatefield, "mmddyy")

i.e. You want to format the current date

strDate = Format(Now(), "mmddyy")
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6488336
You can use the Format$ function:

NewDate = Format$(OldDate,"MMDDYY")
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6488342
First, I'd recommend using a date-picker function so that you don't have to validate the date (since it can be in many different formats.)

Once you have a date in date format (CDate will do that), you can use Month(TheDate), Day(TheDate), Year(TheDate), then tack these pieces together.

Alternately, you can convert the date to a string, then extract the pieces:

left$(MyDate,2) & mid$(MyDate, 4,2) & right$(MyDate,2)
0
 

Author Comment

by:ahelgeson
ID: 6488350
This is exactly what I was looking for!

Thanks!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

785 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