473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting dates in text format to dates

Hello. I need to convert dates in this format to recognizable dates:

20121102 (formatted in text).

In Excel, the conversion formula is =DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

I can not figure out how to convert them in Access.

Thanks!
Nov 2 '12 #1
4 3844
Frinavale
9,735 Expert Mod 8TB
Consider using the Format function to format the string number into an acceptable date string that you can pass to the cdate function.


-Frinny
Nov 2 '12 #2
TheSmileyCoder
2,322 Expert Mod 2GB
There is probably alot smarter ways to do this but you could try:

Expand|Select|Wrap|Line Numbers
  1. Public Function ConvertDate(strDate As String) As Date
  2.   Dim intYear As Integer
  3.   Dim intMonth As Integer
  4.   Dim intDay As Integer
  5.   intYear = Left(strDate, 4)
  6.   intMonth = Mid(strDate, 5, 2)
  7.   intDay = Right(strDate, 2)
  8.   Dim s As String
  9.   s = "" & intMonth & "/" & intDay & "/" & intYear
  10.   ConvertDate = CDate(s)
  11.  
  12. End Function
This video will show you how to implement custom functions in access.
Nov 2 '12 #3
Stewart Ross
2,545 Expert Mod 2GB
If you want to do the conversion in an Access query you can use a computed field based on the DateSerial function in Access that is very similar to the Date function in Excel which you quote.

The SQL would be something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   [YourDate], 
  3.    DateSerial (Left([YourDate], 4), Mid([YourDate], 5, 2), Right([YourDate], 2)) AS YourRealDate
  4. FROM
  5.   [YourTable];
The names of the actual fields and the table or query concerned would have to be used in place of the examples above, but it might get you started without having to define a custom function first.

If you use the Access query editor you can enter the following in the Field Name part of the grid to create the computed field:

Expand|Select|Wrap|Line Numbers
  1. YourRealDate: DateSerial (Left([YourDate], 4), Mid([YourDate], 5, 2), Right([YourDate], 2))
-Stewart
Nov 2 '12 #4
TheSmileyCoder
2,322 Expert Mod 2GB
I had forgotten about the DateSerial function. Thanks for the reminder.
Nov 2 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Christophe Cerbourg | last post by:
hi, Bonjour, I'm using PHPMailer class to send mails and it works fine for HTML ones. But I can't manage to send correctly a text formatted mail... I tried this : - $message = "first...
3
by: Ciar?n | last post by:
I have a table with over a million rows and one of the fields contains amounts of money in text format. What is the most efficient way of converting this field to a number format that I can sum...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
1
by: charliewest | last post by:
Hello - I am pulling a datetime var from a dataset which is binded to a repeater control as follows: <%# DataBinder.Eval(Container.DataItem, "DateCreated") %> The datetime value returns...
2
by: jakub.bauer | last post by:
Hi, I have a table with in MS SQL database. A table consist a list of items bought by a customer with, item prices, item nubers etc. I would like to send an email with a list of items in the...
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i donīt need the time data i would like to...
2
by: Mallik02 | last post by:
Hi I am new to MS-Access, I am getting the date in text format when I export it from other application. Could you please explain if there is any "Query" in Access to convert the text dates into...
4
by: Charlote | last post by:
Hello, I am a beginner in python, and have a question.. I need to create a list of all dates between two dates.. Lets say beggining date= 2008-1-15 enddate= 2008-2-20 how do I...
4
by: Jeff | last post by:
Hey I'm wondering how the Fixed-Width Text Format is What I know is that the top line in this text format will contain column names. and each row beneath the top line represent for example a...
0
by: Bill Eberle | last post by:
In Access 2007 ADP connected to SQL Server Express, most forms allow Text Format attribute of Rich Text, but a few do not. In each case the SQL Server table field connected to the Access Text Box is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.