473,405 Members | 2,272 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,405 software developers and data experts.

Date Conversion from Format YYYMMDD

I have dates in the format of YYYMMDD that I would like to convert into an actual date. The first digit indicates that the date is after 2000 if it is a 1 and prior to 2000 if it is a 0. So for instance: 1011023 = 10/23/2001.

I can convert it using the following statement in an Access query:

Expand|Select|Wrap|Line Numbers
  1. newDate: IIf(Val(Nz([ARN-CREATE-DATE1]))>0,CDate(Mid([ARN-CREATE-DATE1],4,2) & "/" & Mid([ARN-CREATE-DATE1],6,2) & "/" & IIf(Mid([ARN-CREATE-DATE1],1,1)="1","20","19") & Mid([ARN-CREATE-DATE1],2,2)),Null)
Is there a faster or just a cleaner way of converting this date?

-Kyle
Jun 3 '09 #1
5 4046
ChipR
1,287 Expert 1GB
Not sure how much better this is, but I'd probably do:
Expand|Select|Wrap|Line Numbers
  1. newDate: DateSerial(
  2.    1900 + 100 * Left([ARN-CREATE-DATE1],1) + Mid([ARN-CREATE-DATE1], 2, 2), 
  3.    Mid([ARN-CREATE-DATE1], 4, 2),
  4.    Right([ARN-CREATE-DATE1], 2))
Do you have nulls, numbers not greater than 0, and dates in your data? If not, that part can possibly be rewritten.
Jun 3 '09 #2
@ChipR
This is very clever. Thanks for your help. Each field is either null or a date. So I can just evaluate it using an IsNull and if it returns False, use this statement.

Thank you.

-Kyle
Jun 3 '09 #3
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. newDate: DateSerial(1900+Left([ARN-CREATE-DATE1],3),
  2.                     Mid([ARN-CREATE-DATE1],4,2),
  3.                     Right([ARN-CREATE-DATE1],2))
Jun 4 '09 #4
@NeoPa
Suddenly my whole world makes more sense. The first three digits of the date indicate how many years PAST 1900 the year is. I never saw that until now!

Thanks for helping me clean this up! This eliminates a serious amount of function calls. You two are the best.

-Kyle
Jun 4 '09 #5
NeoPa
32,556 Expert Mod 16PB
@servantofone
Always a pleasure Kyle.

Sometimes just the layout of the display can make the difference to how easy it is to follow.
Jun 4 '09 #6

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

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
7
by: Niall Porter | last post by:
Hi all, I'm building an ASP app on a Windows 2000/IIS machine which interfaces with our SQL Server 2000 database via OLE DB. Since we're based in the UK I want the users to be able to type in...
1
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set...
3
by: josh3006 | last post by:
Hi there I'm new in DB2, currently i'm into java development The problem that i'm facing is that when i use JSP page to save, the date is correct when i pass(from JSP page) to database, but when i...
3
by: levinepw | last post by:
I can convert a yymmdd to (yymmdd - 1 day) What I do is take the existing yymmdd string, convert it to a mm/dd/yyyy date and subtract a day from it & then format it back into yyymmdd. But the...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
10
by: =?Utf-8?B?TWlrZQ==?= | last post by:
I have a string variable containing a date formatted as YYYYMMDD For example - Dim x as string = "20070314" If I try to perform a type conversion as follows I get an error: Dim y as Date =...
3
by: Phil H | last post by:
I have a string variable "1/2/2007". What is the easiest way to convert it to "20070102". In VB6, I could cat it to to date and format. Is there equiv C# code to do that. I don't want to do any...
7
by: gerles | last post by:
I need to get the current date and put it into the following format: yyymmdd tttttt I then need to subtract 24 hours from it and so that I can use that time for an SQL query. Any help would be...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.