Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Date Field 1

Status
Not open for further replies.

kupz

Technical User
Aug 23, 2001
24
US
I am having trouble converting a date field. Basically, I am trying to convert a date field called ship date and be able to separate the month and year into two new fields using the month and year functions. The problem is the data format is new to me because the system that generates the date formats it as (CYYMMDD). So for example, a ship transaction with a date of 8/6/01 will come in as 1010806. This is something I've never encountered before and tried different sorts of functions for it to work. I am new to VB/VBA and still trying to learn can you help?
 
This looks like a string field instead of a date. Try the Mid function.
 
1010806; YYMMDD

'assume' the datefield is 'CentDate', then

MyCent: Left([CentDate], 1)
MyYr: Mid([CentDate], 2, 2)
MyMnth: Mid([CentDate], 4, 2)
MyDay: Mid([CentDate], 6, 2)


Translating to podw (Plain Old Debug Window), for illustration:
CentDate = "1010806"
MyCent = Left(CentDate, 1)
MyYr = Mid(CentDate, 2, 2)
MyMnth = Mid(CentDate, 4, 2)
MyDay = Mid(CentDate, 6, 2)
? MyCent, MyYr, MyMnth, MyDay
1 01 08 06
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
That's just great! I was making it harder that it seemed. Thanks to you both.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top