I have tried every function that seemed applicable and can't seem to convert
a simple text field containing numbers, for example "022807", into a date.
Nor can I do the reverse and convert a date field into text, like 02/28/07
into text "022807". Can anyone help? 8 32334
Try:
CDate(Format([MyField], "00\/00\/00"))
The Format() converts the string into a string with embedded slashes.
CDate() then converts it into a date.
Use criteria to filter out nulls.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Steve Cartnal" <sc******@alltel.netwrote in message
news:94***************************@ALLTEL.NET...
>I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
x = "022807"
y = dateserial(mid(x,5,2), left(x,2), mid(x,3,2))
? y
2/28/07
z = format(y, "mmddyy")
? z
022807
This MSKB article provides information on how dates are stored in Access. http://support.microsoft.com/kb/q130514/
HTH - Bob
Steve Cartnal wrote:
>I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
--
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200703/1
Thanks Allen. That works. I had tried the CDate function, and I did get a
date. It just wasn't the date I wanted. Adding the slashes first makes much
sense, but I don't believe that I would have ever thought of trying that on
my own. Thanks much.
"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:45***********************@per-qv1-newsreader-01.iinet.net.au...
Try:
CDate(Format([MyField], "00\/00\/00"))
The Format() converts the string into a string with embedded slashes.
CDate() then converts it into a date.
Use criteria to filter out nulls.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Steve Cartnal" <sc******@alltel.netwrote in message
news:94***************************@ALLTEL.NET...
>>I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
Thanks much Bob. I'll try those when I get a chance.
I could be wrong, but in the second example, wouldn't that still be a date
and not text? (My problem centered on exporting records containing several
date fields. All but one of the dates is to be formatted as "YYYYMMDD". The
odd ball is suppose to be "MMDDYY". So when I set up my export specification
and specified date fields to be YMD and checked the box to use four-digit
years, as they all were suppose to be except that one, the oddball followed
all the others. The field size in the export spec. for that field is 6, so I
would get "200702", instead of "022807". So I figured I could just convert
the date to text somewhere in the process, and can't get that to work. I
believe Access would treat your second example as a date still and when it
was exported to the text file it would be the same as I'm getting now.
"raskew via AccessMonster.com" <u28575@uwewrote in message
news:6e8679e8c8906@uwe...
>x = "022807"
y = dateserial(mid(x,5,2), left(x,2), mid(x,3,2))
? y
2/28/07
z = format(y, "mmddyy")
? z
022807
This MSKB article provides information on how dates are stored in Access. http://support.microsoft.com/kb/q130514/
HTH - Bob
Steve Cartnal wrote:
>>I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
--
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200703/1
On Mar 1, 12:34 am, "Steve Cartnal" <scart...@alltel.netwrote:
I have tried every function that seemed applicable and can't seem to convert
a simple text field containing numbers, for example "022807", into a date.
Nor can I do the reverse and convert a date field into text, like 02/28/07
into text "022807". Can anyone help?
This may not be the best way, but it works. Try it and see if you
like it
Dim Date1 As String, Date2 As String, Date3 As String
Date1 = "022807"
Date2 = Left(Date1, 2) + "/" + Mid(Date1, 3, 2) + "/" + Right(Date1,
2)
Date3 = Replace(Date2, "/", "")
msgbox "Date1 = " & Date1 & vbCrLf & "Date2 = " & Date2 & vbCrLf &
"Date3 = " & Date3
Steve -
The second example if fact returns a number formated with a leading zero. To
return it as text, use the Cstr() function, e.g.
z = cstr(format(y, "mmddyy"))
To test: try ? cdbl(z). It will return a data type mismatch because z is now
in text.
Bob
Steve Cartnal wrote:
>Thanks much Bob. I'll try those when I get a chance.
I could be wrong, but in the second example, wouldn't that still be a date and not text? (My problem centered on exporting records containing several date fields. All but one of the dates is to be formatted as "YYYYMMDD". The odd ball is suppose to be "MMDDYY". So when I set up my export specification and specified date fields to be YMD and checked the box to use four-digit years, as they all were suppose to be except that one, the oddball followed all the others. The field size in the export spec. for that field is 6, so I would get "200702", instead of "022807". So I figured I could just convert the date to text somewhere in the process, and can't get that to work. I believe Access would treat your second example as a date still and when it was exported to the text file it would be the same as I'm getting now.
>>x = "022807" y = dateserial(mid(x,5,2), left(x,2), mid(x,3,2))
[quoted text clipped - 15 lines]
>>>Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
--
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200703/1
I stand corrected. I went back to the underlying table and switched the
oddball date field from a Date/Time to a Text data type, and then used
=Format(Date(), "mmddyy") as the default value and it does behave as text
then and exports just like I need it to. However, I discovered tonight that
the export specifications for those twelve tables still think that field is
a Date field and won't export it. So now I get to go redo all twelve of the
export specs.
"raskew via AccessMonster.com" <u28575@uwewrote in message
news:6e8c8d9f3dd8c@uwe...
Steve -
The second example if fact returns a number formated with a leading zero.
To
return it as text, use the Cstr() function, e.g.
z = cstr(format(y, "mmddyy"))
To test: try ? cdbl(z). It will return a data type mismatch because z is
now
in text.
Bob
Steve Cartnal wrote:
>>Thanks much Bob. I'll try those when I get a chance.
I could be wrong, but in the second example, wouldn't that still be a date and not text? (My problem centered on exporting records containing several date fields. All but one of the dates is to be formatted as "YYYYMMDD". The odd ball is suppose to be "MMDDYY". So when I set up my export specification and specified date fields to be YMD and checked the box to use four-digit years, as they all were suppose to be except that one, the oddball followed all the others. The field size in the export spec. for that field is 6, so I would get "200702", instead of "022807". So I figured I could just convert the date to text somewhere in the process, and can't get that to work. I believe Access would treat your second example as a date still and when it was exported to the text file it would be the same as I'm getting now.
>>>x = "022807" y = dateserial(mid(x,5,2), left(x,2), mid(x,3,2))
[quoted text clipped - 15 lines]
>>>>Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
--
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200703/1
"chris" <ch****@motors-acceptance.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
On Mar 1, 12:34 am, "Steve Cartnal" <scart...@alltel.netwrote:
>I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date field into text, like 02/28/07 into text "022807". Can anyone help?
This may not be the best way, but it works. Try it and see if you
like it
Dim Date1 As String, Date2 As String, Date3 As String
Date1 = "022807"
Date2 = Left(Date1, 2) + "/" + Mid(Date1, 3, 2) + "/" + Right(Date1,
2)
Date3 = Replace(Date2, "/", "")
msgbox "Date1 = " & Date1 & vbCrLf & "Date2 = " & Date2 & vbCrLf &
"Date3 = " & Date3
Thanks Chris. I will try that. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
7 posts
views
Thread by Dana Shields |
last post: by
|
5 posts
views
Thread by Robert |
last post: by
|
32 posts
views
Thread by robert d via AccessMonster.com |
last post: by
|
2 posts
views
Thread by XML newbie: Urgent pls help! |
last post: by
|
12 posts
views
Thread by Rob Meade |
last post: by
|
2 posts
views
Thread by TofuTheGreat |
last post: by
|
3 posts
views
Thread by Jef Driesen |
last post: by
|
1 post
views
Thread by PW |
last post: by
| | | | | | | | | | | |