Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-01
17
Medium Priority
?
1,371 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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 52

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 52

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

650 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