Solved

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

Posted on 2009-04-01
17
1,350 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 50

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 50

Accepted Solution

by:
Gustav Brock earned 500 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

749 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