Solved

Formatting data into date  / query

Posted on 2012-04-13
3
277 Views
Last Modified: 2012-04-16
I have a text field that contains data in yyyymmddhhmmss format.

I need a query to return me anything from yesterday


20120312000000  =- sample data
20120312000014
20120312000002
0
Comment
Question by:hwassinger
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 37843318
Your criteria could be WHERE Left(TheTable.TheField,8)  = "20120412"

So, look at the 8 leftmost characters, and then make a match.
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 37843332
If you needed it to be dynamic, as in always yesterday from anytime onward
WHERE Left(TheTable.TheField,8)  =format(DateSerial(Year(Date()), Month(Date()) , Day(Date())-1),"yyyymmdd")
should do it
0
 
LVL 58

Expert Comment

by:harfang
ID: 37852005
If today is 2012-04-16, yesterday is 2012-04-15, or Date()-1. For a text field, and in order to avoid calculations on the field content, try:

WHERE YourField Between Format(Date()-1, 'yyyymmdd') And Format(Date(), 'yyyymmdd')

This will evaluate to

WHERE YourField Between '20120415' And '20120416'

If you have an index on YourField, it will be used in the query's execution plan. This is the only difference with Nick67's solution.

Cheers!
(°v°)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now