473,387 Members | 1,693 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,387 software developers and data experts.

How to combine two Microsoft Access date fields into one

I have a Start Date field and a End date field in one of my tables. I have a report that I created and I want to combine the two fields into one so that it reads as follows:

01/01/2010 to 12/31/2010

This is the expression I'm using: =[Previous Start Date] & " to " & +[PrevAssnEnd]

The problem is, for those records with no data values the word "to" is showing up in the field and I want the field to remain blank if the field is empty.
Nov 4 '10 #1
9 6277
NeoPa
32,556 Expert Mod 16PB
LeeLee:
The problem is, for those records with no data values the word "to" is showing up in the field and I want the field to remain blank if the field is empty.
How can this make sense when there are two fields? Please make the question make sense.

Also, is the plus sign (+) in =[Previous Start Date] & " to " & +[PrevAssnEnd] simply a mistake? If not, the question makes even less sense than I thought.

Assuming you have the commonest form of this issue, you may want to try :
Expand|Select|Wrap|Line Numbers
  1. =[Previous Start Date] & ' to ' + [PrevAssnEnd])
See Using "&" and "+" in WHERE Clause for more on why that will have the effect I think you're after.
Nov 4 '10 #2
gnawoncents
214 100+
Try this:

Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNull([Previous Start Date]),([Previous Start Date] & " to " & [PrevAssnEnd]),Null) 
Nov 4 '10 #3
SO that means if one of the dates are blank then nothing should be shown:


This could do that.
Expand|Select|Wrap|Line Numbers
  1. =IIF(Isnull([Previous Start Date]or isnull([PrevAssnEnd],Null,[Previous Start Date] & " to " & [PrevAssnEnd])
Nov 4 '10 #4
colintis
255 100+
Rozeanna, you forgot some close brackets for the IsNulls =)

Expand|Select|Wrap|Line Numbers
  1. =IIF(IsNull([Previous Start Date])OR IsNull([PrevAssnEnd]),Null,[Previous Start Date] & " to " & [PrevAssnEnd])
Nov 5 '10 #5
NeoPa
32,556 Expert Mod 16PB
I know the question wasn't well asked and was quite ambiguous, but it's rare for end dates to exist in situations where start dates don't (not impossible but extremely rare in real life situations).

With this in mind one can guess that what is required is to handle the absence of an end date (rather than the start date as post #3 almost handles). To do this it is absolutely not necessary to check for nulls using either IsNull() or Nz(), but the simple expedient of using the plus (+) character as a concatenator will work (as already illustrated in post #2 and fully explained in the linked article).

If the guess is wrong (who can't say for sure unless and until the OP clarifies the question), then implementing displaying the string only if both values are non-null is even more straightforward :
Expand|Select|Wrap|Line Numbers
  1. =[Previous Start Date] + ' to ' + [PrevAssnEnd])
There really is no need to over-complicate matters by using a bunch of function calls.
Nov 5 '10 #6
gnawoncents
214 100+
NeoPa,

Thanks for the "+" tip. I hadn't seen that one before and will definitely use it in my future work. Also, sorry to post on top of you -- I failed to refresh the page and see if anyone had posted a solution before posting mine.

-------

Leelee,

NeoPa is absolutely correct (no surprise there). If you are working with text values, go with his solution. It is much cleaner. However, if you are using date fields, you can use an IIf statement; but don't use my first one since I got the Null backwards, and as NeoPa pointed out, should probably be looking at the end date for Null. Instead try:

Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNull([PrevAssnEnd]),Null,([Previous Start Date] & " to " & [PrevAssnEnd])) 
Finally, as NeoPa said,
who can say for sure unless and until the OP clarifies the question
Nov 5 '10 #7
NeoPa
32,556 Expert Mod 16PB
GnawOnCents:
However, if you are using date fields,
I hate to disabuse, as you certainly seem to be grappling with the issues, but as the result is textual, the original form of the fields shouldn't really come into it. The point is that the requirement is for a textual result. If you were looking to use IsNull() then you would want to make sure that if the end date is null then both the end date, and the string ' to ', were both dropped from the result (It's possible to use double-quotes (") in Access SQL but the standard is to use single quotes (')). This doesn't seem to be the result of the code posted. Sorry.
Nov 5 '10 #8
gnawoncents
214 100+
NeoPa,

Please excuse my ignorance. I had tried the + signs and got errors whenever dates were used in both source fields, but am likely just missing something.

Regarding the single quotes, I hadn't heard it was preferred to use them in place of double quotes. After reading your comment, I read your insight on single vs double quotes and learned a few things. Once again, thank you for your expert advice.
Nov 6 '10 #9
NeoPa
32,556 Expert Mod 16PB
I suspect this is down to Access automatically converting things where it detects a need. Typically, adding dates to a string (particularly concatenating using the &) is easily recognised as requiring the date value to be converted to text (using the default date format). I expect that the plus concatenation char (+) may cause some confusion as it is also the addition character. Dates can be considered to be numeric, so unfortunately when it sees the plus char it doesn't treat it as a concatenation instruction at all, but as an addition character instead. As converting the date to a formatted string rather blows out the whole concept, I have to say that my approach won't actually work in this case.

It's a shame, as the longhand version looks and reads quite clumsily :
Expand|Select|Wrap|Line Numbers
  1. =IIf([Previous Start Date] & [PrevAssnEnd]='','',[Previous Start Date] & IIf(IsNull([PrevAssnEnd]),'', ' to ' & [PrevAssnEnd]))
BTW Good catch GnawOnCents.
Nov 6 '10 #10

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

Similar topics

4
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field...
1
by: Miguelito Bain | last post by:
hi everybody. i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and...
5
by: Alan | last post by:
Hello, I trying to export my email to an access database. Outlook already this function, but not all the fields are available once the export is complet. The time & date stamps are not...
2
by: Randy | last post by:
I am trying to make the move from Approach to Microsoft Access and am having real problems with developing forms? Would someone please describe the Access concept of developing forms using...
5
by: QBCM | last post by:
I am trying to create a report by selecting three date fields from one table with records between a start date and end date. I have tried to adapt one of Allen Browne's scripts as follows but it...
2
by: bobc | last post by:
Any help appreciated with this problem -- I have a Microsoft Access 2002 application. The Access mdb has a refence to DAO 3.6 (not ADO). A form is bound to a linked table in a second mdb. In the...
8
by: Ragbrai | last post by:
Howdy All, I have a query that is used for filtering results to be used in a combo box. The query needs to test fields from both a table and then unbound text boxes on the form that also contains...
5
by: trig | last post by:
Please help! I am an ICT teacher at a secondary school and my year 12 (AS Level) group need to create a website where data can be sent from a form to a Microsoft Access database. I am trying...
6
by: Ledmark | last post by:
Hello - I am in a class for Access 2007 Database apllication design and we are covering types of Validation rules. We have a problem that I'm trying to solve but have no idea how to go about writing...
2
by: KMEscherich | last post by:
Microsoft Access 2003 Hi there, am stuck with something that I am not sure on how to get done. I am attempting to have 3 check boxes and have 3 date fields. I need to have each date field 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.