473,399 Members | 3,302 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,399 software developers and data experts.

Convert string to Date

dsatino
393 256MB
I'm getting a tab delimited file that I need to import into an access DB. The date field comes over as an 8 character string in the yyyymmdd format.

Does anyone know an easy way to convert this to a date or a pre-existing function?
May 5 '11 #1
5 22645
TheSmileyCoder
2,322 Expert Mod 2GB
Try the built in function cdate. It should meet your needs
May 5 '11 #2
dsatino
393 256MB
You might think so, but it doesn't convert this to a date. As a string, I get 'expected expression'. As a number I get 'out of range'.

I expected the number to fail, but I thought the string would work.
May 5 '11 #3
Rabbit
12,516 Expert Mod 8TB
That's because the yyyymmdd format isn't a recognized format by Access. Strings without delimiters aren't recognized as dates.
CDate(Mid(strDate, 5,2) & "/" & Right(strDate, 2) & "/" & Left(strDate, 4))
May 5 '11 #4
dsatino
393 256MB
Yeah, I had a feeling this was the route I was going. I was just figuring there was a predefined function. Oh well, I guess I'll just write it. :)
May 5 '11 #5
NeoPa
32,556 Expert Mod 16PB
You can happily use this that I produced a while back :

Expand|Select|Wrap|Line Numbers
  1. 'YMDToDate takes varDate in YYYYMM or YYYYMMDD format and returns it as a date.
  2. '28/01/2004 Return Null if not valid format.
  3. Public Function YMDToDate(varDate As Variant) As Variant
  4.     Dim strDMY As String
  5.  
  6.     strDMY = Mid(varDate, 5, 2) & "/" & Left(varDate, 4)
  7.     If Len(varDate) = 8 Then strDMY = Mid(varDate, 7, 2) & "/" & strDMY
  8.     YMDToDate = Null
  9.     If IsDate(strDMY) Then YMDToDate = CDate(strDMY)
  10. End Function
May 10 '11 #6

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

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
2
by: Abhishek Srivastava | last post by:
Hello All, I wrote the following program. using System; using System.Globalization; public class ShortDateTest { public static void Main(string args)
1
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" ...
1
by: Sam | last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z =...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
2
by: Kakishev | last post by:
I have a problem at how best to convert a Date into a text field and keep the format dd/mmm/yyyy (01-FEB-2007). The problem is that dates are imported from SQL into an access front end Database....
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
5
satiss7pwr
by: satiss7pwr | last post by:
I have a string date like this: "3/28/2008 12:05:45 pm" i want to convert it into date and display the out put any one can help me plssssssssss
3
by: tanishka singh | last post by:
How do you convert string from database into date in asp.net? Dim output = (From tlb In obj.SelectRecordAll_SalesInquiryRegister _ Join tlb1 In LatestPOs On tlb.SIR_OfferNo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.