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: - 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
5 4046
Not sure how much better this is, but I'd probably do: - newDate: DateSerial(
-
1900 + 100 * Left([ARN-CREATE-DATE1],1) + Mid([ARN-CREATE-DATE1], 2, 2),
-
Mid([ARN-CREATE-DATE1], 4, 2),
-
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.
@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
NeoPa 32,556
Expert Mod 16PB
Try : - newDate: DateSerial(1900+Left([ARN-CREATE-DATE1],3),
-
Mid([ARN-CREATE-DATE1],4,2),
-
Right([ARN-CREATE-DATE1],2))
@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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: 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...
| |