A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Format Date



 
 
Thread Tools Display Modes
  #1  
Old May 30th, 2004, 04:39 PM
Tiffany
external usenet poster
 
Posts: n/a
Default Format Date

I have to import a text file into access. When I import
the file using the date format on the table I get import
errors. Since I cannot control the text file data I must
import the field as a general number. As a result I need
to convert the format in the query or report to MM/DD/YYYY
but, I do not know how to do it. Does anybody have any
ideas? Thank You in advance. Tiffany
  #2  
Old May 30th, 2004, 05:28 PM
Jeff Boyce
external usenet poster
 
Posts: n/a
Default Format Date

Tiffany

What is the underlying structure of the "date field"? You describe it as a
"general number", but is it a number like Access uses, or is it a text
string like "20040530"?

Access has a DateSerial(Y,M,D) function you could check into using (try HELP
on DateSerial).


--
Good luck

Jeff Boyce
Access MVP

  #3  
Old May 30th, 2004, 10:36 PM
Tiffany
external usenet poster
 
Posts: n/a
Default Format Date

Jeff it is a text string "20040530". I took your advice
and looked it up in Help but I'm confused I only want to
convert the string into a date. The example returns a
number of days? So this is what I think I should do.


Function ConvertTxtToDate(dteInput As Date) As Integer
Dim intDays As Integer

' Add one month, subtract dates to find difference.
intDays = DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput)) _
DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput))
ConvertTxtToDate = intDays
Debug.Print intDays
End Function

The following is the Sub procedure for the
ConvertTxtToDate function.

Sub CallConvertTxtToDate()
Dim intDays As Integer

intDays = DaysInMonth("4-1-1996")

End Sub


If this is correct then I know I should make a module
called ConvertTxtToDate but I do not know where or how to
put the Sup procedure. In the Query, Report Query, SQL in
the query? If in the SQL then how to add and where? If
anywhere then how to add and where?. Thanks in advance,
Tiffany




-----Original Message-----
Tiffany

What is the underlying structure of the "date field"?

You describe it as a
"general number", but is it a number like Access uses, or

is it a text
string like "20040530"?

Access has a DateSerial(Y,M,D) function you could check

into using (try HELP
on DateSerial).


--
Good luck

Jeff Boyce
Access MVP

.

  #4  
Old May 31st, 2004, 01:51 AM
John Spencer (MVP)
external usenet poster
 
Posts: n/a
Default Format Date

Pardon me for jumping in. As long as your field is never null, you should be
able to use something like the following.

DateSerial(Left(YourField,4),Mid(YourField,5,2),Ri ght(YourField,2))

If it can be null, then

IIF(YourField is Not Null,
DateSerial(Left(YourField,4),Mid(YourField,5,2),Ri ght(YourField,2)), Null)

Tiffany wrote:

Jeff it is a text string "20040530". I took your advice
and looked it up in Help but I'm confused I only want to
convert the string into a date. The example returns a
number of days? So this is what I think I should do.

Function ConvertTxtToDate(dteInput As Date) As Integer
Dim intDays As Integer

' Add one month, subtract dates to find difference.
intDays = DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput)) _
DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput))
ConvertTxtToDate = intDays
Debug.Print intDays
End Function

The following is the Sub procedure for the
ConvertTxtToDate function.

Sub CallConvertTxtToDate()
Dim intDays As Integer

intDays = DaysInMonth("4-1-1996")

End Sub

If this is correct then I know I should make a module
called ConvertTxtToDate but I do not know where or how to
put the Sup procedure. In the Query, Report Query, SQL in
the query? If in the SQL then how to add and where? If
anywhere then how to add and where?. Thanks in advance,
Tiffany


-----Original Message-----
Tiffany

What is the underlying structure of the "date field"?

You describe it as a
"general number", but is it a number like Access uses, or

is it a text
string like "20040530"?

Access has a DateSerial(Y,M,D) function you could check

into using (try HELP
on DateSerial).


--
Good luck

Jeff Boyce
Access MVP

.

  #5  
Old May 31st, 2004, 05:48 AM
Tiffany
external usenet poster
 
Posts: n/a
Default Format Date

John, it worked thank you, Tiffany


-----Original Message-----
Pardon me for jumping in. As long as your field is never

null, you should be
able to use something like the following.

DateSerial(Left(YourField,4),Mid(YourField,5,2),Ri ght

(YourField,2))

If it can be null, then

IIF(YourField is Not Null,
DateSerial(Left(YourField,4),Mid(YourField,5,2),R ight

(YourField,2)), Null)

Tiffany wrote:

Jeff it is a text string "20040530". I took your advice
and looked it up in Help but I'm confused I only want to
convert the string into a date. The example returns a
number of days? So this is what I think I should do.

Function ConvertTxtToDate(dteInput As Date) As Integer
Dim intDays As Integer

' Add one month, subtract dates to find difference.
intDays = DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput)) _
DateSerial(Year(dteInput), _
Month(dteInput), Day(dteInput))
ConvertTxtToDate = intDays
Debug.Print intDays
End Function

The following is the Sub procedure for the
ConvertTxtToDate function.

Sub CallConvertTxtToDate()
Dim intDays As Integer

intDays = DaysInMonth("4-1-1996")

End Sub

If this is correct then I know I should make a module
called ConvertTxtToDate but I do not know where or how

to
put the Sup procedure. In the Query, Report Query, SQL

in
the query? If in the SQL then how to add and where? If
anywhere then how to add and where?. Thanks in advance,
Tiffany


-----Original Message-----
Tiffany

What is the underlying structure of the "date field"?

You describe it as a
"general number", but is it a number like Access uses,

or
is it a text
string like "20040530"?

Access has a DateSerial(Y,M,D) function you could check

into using (try HELP
on DateSerial).


--
Good luck

Jeff Boyce
Access MVP

.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.