Solved

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

Posted on 2009-04-01
17
1,334 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
Comment Utility
What datatype does it show as in the Access table?
0
 

Author Comment

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

Expert Comment

by:BrandonGalderisi
Comment Utility
you REALLY don't want to store dates as integers.
0
 

Author Comment

by:shwelosa
Comment Utility
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
Comment Utility
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
Comment Utility
Use the expression

Val(Format([YourDateField], mmddyy))

It will return an integer.

/gustav
0
 
LVL 44

Expert Comment

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

Expert Comment

by:GRayL
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 44

Expert Comment

by:GRayL
Comment Utility
Sorry, CLng() rounds up.  use Int(fldDate)

UPDATE myTable SET iDate = Int(fldDate);


0
 

Author Comment

by:shwelosa
Comment Utility
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
Comment Utility
hi GrayL,

what is idate?
0
 

Author Comment

by:shwelosa
Comment Utility
hi Cactus data,

How would i code the val stmt?
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
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
Comment Utility
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
Comment Utility
Can you post the SQL of your update query?
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
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
Comment Utility
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)

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now