473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simpler syntax for date conversion

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 expression is a monster beacuse I have to include the DateAdd()
for each part of the formatting.

Exp_date:
Right(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " "
& Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),2) &
Left(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " "
& Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),2) &
Mid(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " " &
Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),4,2)

It would be prettier with a variable instead of having to repeat
DateAdd(). So I tried that. I created an expression Exp_Date1 in a
sperate non-displayed column that just did the DateAdd(). But when I
tried to reference [Exp_Date1] to format it, ACCESS prompted me for the
value. So that's why I use the big ugly.

Any ideas on slimming the expression down? Is there a way to define a
variable in ACCESS expressions?

Mar 23 '06 #1
3 1742
So, why are you keeping a date as a string value? Sometimes I get
string-value-dates as input, but it doesn't make any sense to keep them as
strings in your database.

It's possible, perhaps, to expend time and effort to do this more
efficiently, but I don't like to encourage what may be ill-advised practices
(such as dates in strings).

Larry Linson
Microsoft Access MVP

<le******@yahoo.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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 expression is a monster beacuse I have to include the DateAdd()
for each part of the formatting.

Exp_date:
Right(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " "
& Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),2) &
Left(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " "
& Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),2) &
Mid(DateAdd("d",-1,CDate(Mid([dupe_openTerms_1].[Exp_Date],3,2) & " " &
Right([dupe_openTerms_1].[Exp_Date],2) & " " &
Left([dupe_openTerms_1].[Exp_Date],2))),4,2)

It would be prettier with a variable instead of having to repeat
DateAdd(). So I tried that. I created an expression Exp_Date1 in a
sperate non-displayed column that just did the DateAdd(). But when I
tried to reference [Exp_Date1] to format it, ACCESS prompted me for the
value. So that's why I use the big ugly.

Any ideas on slimming the expression down? Is there a way to define a
variable in ACCESS expressions?

Mar 23 '06 #2
The values are kept as strings in the database because of a documented
bug in ACCESS that won't allow me to import the yymmdd data as dates
from a fixed width text file.

Mar 29 '06 #3
<le******@yahoo.com> wrote
The values are kept as strings in the database
because of a documented bug in ACCESS that
won't allow me to import the yymmdd data as
dates from a fixed width text file.


Bug? Sounds like "working as designed" to me. But, so what?

Once they are imported, it's not rocket science to convert them. You'll only
have to do it once after you input them and it will make your life easier*.

(Example, you won't have to put up with replies
similar to "It can be done but I won't do anything
to encourage bad practices.")

Larry Linson
Mar 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Detlef Jockheck | last post by:
Hi, I would like to check if a string contains a valid date format (Format: "dd.mm.yyyy") or not. What is the best way to do this. regexp? At the moment it would be sufficient to check for...
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...
1
by: Riley DeWiley | last post by:
I have an UPDATE query that is always setting 0 records. When I cut and paste the SQL into Access and use it, it fails in the same way unless I coerce the date fields to be '=now()', in which case...
20
by: pertheli | last post by:
Hello all What is the difference between Method 1 and Method 2 below? Is Method 2 safe to use? typedef short Word; typedef unsigned char Char; int nAllocSize = large number;
11
by: KavvY | last post by:
Hi Can anyone tell me why I get a SQL syntax error with the following code? string strInsert = "INSERT INTO dateEntry (entry, date) VALUES ('test3', '17/08/2004')"; OleDbCommand cmd = new...
20
by: Fred Hebert | last post by:
I am trying to learn VC.NET and convert some Borland C++ applications. The syntax differences are killing me... Is there an easy way to convert a hex string, entered by the user, to a binary...
6
by: Scott Nixon | last post by:
New to Postgres 7.3 from 7.0. Am having some trouble with a query that worked in 7.0 but not in 7.3.....can't seem to figure out the syntax or find info about how to do this anywhere. ...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.