Date query

okl

Board Regular
Joined
Jan 17, 2008
Messages
52
Office Version
  1. 365
Platform
  1. Windows
hi
I have a table with a date field ddmmyyyy hhmmss from year 2014 and year 2015

If I want to query on certain date e.g year to date for 2015 : 01/01/2015 00:00 to 28/08/2015 2359

How can I do the same for year 2014 too from the same table .

Purpose is to compare the mtd or ytd value of two different years.


Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
=EDATE(A1,-12)+"23:59"
Excel solutions usually will not work for Access questions!;)

I have a table with a date field ddmmyyyy hhmmss from year 2014 and year 2015
So are you fields actually entered as Text data type or Date data type?
 
Upvote 0
If your table date/time field does in fact contain the time component one often needs to deal with it when supplying an end date to your query.
For a range from a date to end of year, it is simply >=#01/01/2015 - no end date required.

For a range between two dates (where the date comes from a form control):
Between [Forms]![Switchboard]![StartDate] And DateAdd("n",1440,[Forms]![Switchboard]![EndDate])
The DateAdd function adds a date/time value to the EndDate. In this case, it is 1440 (60min*24hrs) minutes (n). Otherwise, the cutoff point would be at the zero hour of the end date. You could get this down to the last second by adding the appropriate number of seconds to the date if need be. For my purpose, no one would be doing anything that creates records that late in the day, so I probably went overboard anyway.

For a date range between dates where the field does not contain the time component, it would be:
Between #01/01/2015# And #08/01/2015#
 
Upvote 0
Data data type ?
No, I said "Date Data Type".

If you open up your table in Design View, does it show your field's Data Type as "Text" or "Date/Time"?
Many times, if dates in a "weird" format, the field is stored as Text (and the user may not be fully aware of it).
The Data Type of the field affects how you would approach your question.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,847
Messages
6,162,380
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top