Solved

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

Posted on 2009-04-01
17
1,346 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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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 49

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 49

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

773 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