Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Breaking down a date

Posted on 2001-09-17
4
Medium Priority
?
161 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 400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
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…

885 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