?
Solved

how do i convert an access date/time field value to integer?

Posted on 2009-04-01
17
Medium Priority
?
1,362 Views
Last Modified: 2012-05-06
I imported a  text file from a lotus approach database into ms access.  the date field is 1/27/1995 and i would like to convert it to an integer date field where it will read 12795.  From there i will export the data to a sql table where it is defined as an integer.  Please help.
0
Comment
Question by:shwelosa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +2
17 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 24043124
What datatype does it show as in the Access table?
0
 

Author Comment

by:shwelosa
ID: 24043182
some of the date fields show as date/time and some as text.  
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24043650
you REALLY don't want to store dates as integers.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:shwelosa
ID: 24043697
i know.  however, it is what i have to deal with.  The program that is reading this table is a combination of cobol and sql.  sorry.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24043721
Well the SQL to convert that would be

select cast(replace(convert(varchar(10), YourDateField, 1) ,'/','') as int)

I don't know how you are loading it into SQL though
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 24043970
Use the expression

Val(Format([YourDateField], mmddyy))

It will return an integer.

/gustav
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24044175
Use CInt(fldDate) - is all you need
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24044214
Sorry, the date now exceeds Integer limitations.  Use CLng(fldDate).  In your table create a Long field named lDate and run this query:

Update myTable SET lDate= CLng(fldDate)


0
 
LVL 44

Expert Comment

by:GRayL
ID: 24044232
Sorry, CLng() rounds up.  use Int(fldDate)

UPDATE myTable SET iDate = Int(fldDate);


0
 

Author Comment

by:shwelosa
ID: 24044285
hi Brandon,

when i used the cast suggestion in access, i get an error.  it is syntax error (missing operator) in query expression tablename.cast(replace(convert(varchar(10), mydadefield, 1) ,'/','') as int).  pls help.
0
 

Author Comment

by:shwelosa
ID: 24044328
hi GrayL,

what is idate?
0
 

Author Comment

by:shwelosa
ID: 24044343
hi Cactus data,

How would i code the val stmt?
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24044419
It was supposed to be the new field you created in the table.  Just so all prefixes add up, we create a new field in the table named fldDateLng (Integer won't cut it).  Then we run this query:

UPDATE myTable SET fldDateLng=Int(fldDate);

Note the Int() function produces the integer value of a number, not an Integer datatype.
0
 

Author Comment

by:shwelosa
ID: 24044644
hi GrayL,
it is asking me to enter the value for flddatelng and if i tried to enter the value of 1 record, it says that the field is not updateable.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24045480
Can you post the SQL of your update query?
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1500 total points
ID: 24047084
Too much confusion here.

1. The integer value requested is not the numeric value of a date value but a value from the formatted date. Thus values will fall between 10100 and 123199 and the data type of the new field must be Long.

2. The conversion is taking place in Access. Thus an update query will use Access SQL.

3. Data export will happen later.

So all that is needed is a simple update query in Access:

UPDATE
  tblYourTable
SET
  YourLongField = Val(Format([YourDateField], mmddyy));

/gustav
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24051550
You have to use your own table and field names, replacing myTable, fldDate and fldDateLng accordingly
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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