Microsoft Access Convert Numbers to Dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Someone just gave me an old database to work on, and the dates are all stored
in text fields with values like 990921. How can I convert these over to
regular Access dates?
 
If you've inherited a database that has dates in a text field, with a format
like 990102 for Jan-2-1999, you need to convert those to regular Access date
fields.

Add a new blank DATE field to your table to store your new value. My old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID functions to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) & "/" &
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries as there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter
 
Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is ymmdd. I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly. I have
played with the positions and I can't seem to figure out the correlations.
Help.

Pieter Wijnen said:
Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


Amicron said:
If you've inherited a database that has dates in a text field, with a
format
like 990102 for Jan-2-1999, you need to convert those to regular Access
date
fields.

Add a new blank DATE field to your table to store your new value. My old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) & "/" &
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
try format function format([fieldname],"dd/mm/yyyy")
if that still not works there must be a function to convert the resulting
text to dates
 
DateSerial(YearPart,MonthPart,DayPart)

ie

RESERVATIONDATE: DateSerial(Left([Res Dateyy],2),Mid([Res
Dateyy],3,2),Right([Res Dateyy],2)

HTH

Pieter

Bunky said:
Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is ymmdd.
I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly. I
have
played with the positions and I can't seem to figure out the correlations.
Help.

Pieter Wijnen said:
Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


Amicron said:
If you've inherited a database that has dates in a text field, with a
format
like 990102 for Jan-2-1999, you need to convert those to regular Access
date
fields.

Add a new blank DATE field to your table to store your new value. My
old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID
functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) & "/"
&
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do
this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
Just when I thought I understood...
I am comparing the reservationdate and the checkindate (done the same way as
what you showed below). I add 5 months to the reservationdate and then do a
compare against the checkindate. If the checkindate is any month other than
9, the compare is working fine but when the checkindate month is 9, it is
comparing higher than the reservationdate +5 months

Reservation Date Reservation Date + 5 Checkindate Result
9/17/2007 2/17/2008 10/5/2007 low
9/17/2007 2/17/2008 9/26/2007 high

It should show a low comparison against the Reservation Date + 5 months.
Any idea why it is showing incorrectly?
Pieter Wijnen said:
DateSerial(YearPart,MonthPart,DayPart)

ie

RESERVATIONDATE: DateSerial(Left([Res Dateyy],2),Mid([Res
Dateyy],3,2),Right([Res Dateyy],2)

HTH

Pieter

Bunky said:
Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is ymmdd.
I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly. I
have
played with the positions and I can't seem to figure out the correlations.
Help.

Pieter Wijnen said:
Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


If you've inherited a database that has dates in a text field, with a
format
like 990102 for Jan-2-1999, you need to convert those to regular Access
date
fields.

Add a new blank DATE field to your table to store your new value. My
old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID
functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) & "/"
&
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do
this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
You should also have a look at the DateAdd & DateDiff Functions

Pieter

Bunky said:
Just when I thought I understood...
I am comparing the reservationdate and the checkindate (done the same way
as
what you showed below). I add 5 months to the reservationdate and then do
a
compare against the checkindate. If the checkindate is any month other
than
9, the compare is working fine but when the checkindate month is 9, it is
comparing higher than the reservationdate +5 months

Reservation Date Reservation Date + 5 Checkindate Result
9/17/2007 2/17/2008 10/5/2007
low
9/17/2007 2/17/2008 9/26/2007
high

It should show a low comparison against the Reservation Date + 5 months.
Any idea why it is showing incorrectly?
Pieter Wijnen said:
DateSerial(YearPart,MonthPart,DayPart)

ie

RESERVATIONDATE: DateSerial(Left([Res Dateyy],2),Mid([Res
Dateyy],3,2),Right([Res Dateyy],2)

HTH

Pieter

Bunky said:
Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is
ymmdd.
I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly.
I
have
played with the positions and I can't seem to figure out the
correlations.
Help.

:

Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


If you've inherited a database that has dates in a text field, with
a
format
like 990102 for Jan-2-1999, you need to convert those to regular
Access
date
fields.

Add a new blank DATE field to your table to store your new value. My
old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID
functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) &
"/"
&
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries
as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do
this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
I used the DateAdd to add the 5 months but did a regular iif stmt for the
comparison. Thanks a bunch. I will look into the DateDiff.

Pieter Wijnen said:
You should also have a look at the DateAdd & DateDiff Functions

Pieter

Bunky said:
Just when I thought I understood...
I am comparing the reservationdate and the checkindate (done the same way
as
what you showed below). I add 5 months to the reservationdate and then do
a
compare against the checkindate. If the checkindate is any month other
than
9, the compare is working fine but when the checkindate month is 9, it is
comparing higher than the reservationdate +5 months

Reservation Date Reservation Date + 5 Checkindate Result
9/17/2007 2/17/2008 10/5/2007
low
9/17/2007 2/17/2008 9/26/2007
high

It should show a low comparison against the Reservation Date + 5 months.
Any idea why it is showing incorrectly?
Pieter Wijnen said:
DateSerial(YearPart,MonthPart,DayPart)

ie

RESERVATIONDATE: DateSerial(Left([Res Dateyy],2),Mid([Res
Dateyy],3,2),Right([Res Dateyy],2)

HTH

Pieter

Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is
ymmdd.
I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly.
I
have
played with the positions and I can't seem to figure out the
correlations.
Help.

:

Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


If you've inherited a database that has dates in a text field, with
a
format
like 990102 for Jan-2-1999, you need to convert those to regular
Access
date
fields.

Add a new blank DATE field to your table to store your new value. My
old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID
functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) &
"/"
&
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries
as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do
this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 
Pieter,

I looked into several Date functions but did not see anything like what I
need.
I need to look at the reservation date and compare it to the check in date.
If the difference is greater than 5 months and the number of nights staying
is less than 7, it is an error. One problem is if the reservation date is
9/17/07 and to get the 5 months out does not actually compute to 5 months.
Our MainFrame adds 5 to the month field, subtracts 12 if it goes over, and
tells everyone 5 months from 9/17/07 is 2/17/08. So I want to see if the
difference between the reservation date and the check in date is greater than
5 months and the number of nights is less than 7. Is there an easy way to do
this?

Thanks for your help!

Bunky said:
I used the DateAdd to add the 5 months but did a regular iif stmt for the
comparison. Thanks a bunch. I will look into the DateDiff.

Pieter Wijnen said:
You should also have a look at the DateAdd & DateDiff Functions

Pieter

Bunky said:
Just when I thought I understood...
I am comparing the reservationdate and the checkindate (done the same way
as
what you showed below). I add 5 months to the reservationdate and then do
a
compare against the checkindate. If the checkindate is any month other
than
9, the compare is working fine but when the checkindate month is 9, it is
comparing higher than the reservationdate +5 months

Reservation Date Reservation Date + 5 Checkindate Result
9/17/2007 2/17/2008 10/5/2007
low
9/17/2007 2/17/2008 9/26/2007
high

It should show a low comparison against the Reservation Date + 5 months.
Any idea why it is showing incorrectly?
:

DateSerial(YearPart,MonthPart,DayPart)

ie

RESERVATIONDATE: DateSerial(Left([Res Dateyy],2),Mid([Res
Dateyy],3,2),Right([Res Dateyy],2)

HTH

Pieter

Obviously, I am not following the DateSerial command.
I have a date that is stored on the table in text. It's format is
ymmdd.
I
have made it yymmdd. Then I tried to
RESERVATION DATE: Format(DateSerial(Right([Res Dateyy],2),Mid([Res
Dateyy],3,2),Left([Res Dateyy],2))) and it does not format correctly.
I
have
played with the positions and I can't seem to figure out the
correlations.
Help.

:

Safer is
DateSerial(Left([CustomerDOB],2), Mid([CustomerDOB],3,2),
Right([CustomerDOB],2))
As you don't have to worry about the regional settings

Pieter


If you've inherited a database that has dates in a text field, with
a
format
like 990102 for Jan-2-1999, you need to convert those to regular
Access
date
fields.

Add a new blank DATE field to your table to store your new value. My
old
date is in the text field CustomerDOB, so I'll add a new one called
NewCustomerDOB.

Now I'll create an UPDATE QUERY using the LEFT, RIGHT, and MID
functions
to
put the date together:

Update to: Right([CustomerDOB],2) & "/" & Mid([CustomerDOB],3,2) &
"/"
&
Left([CustomerDOB],2)

Be sure to back up your database before running any update queries
as
there
is always the possibility of data loss!

I actually have a video tutorial on my web site that shows how to do
this:

<a
href="http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp?key=MSForum">Microsoft
Access Convert Numbers To Dates</a>

http://599cd.com/tips/access/AC309-convert-numbers-to-dates.asp


Hope this helps.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top