Solved

Formatting data into date  / query

Posted on 2012-04-13
3
279 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Before insert Image (OLE) resize image 11 41
combine ShipTo and BillTo Address 3 22
SQL profiler equivalent in MS-Access 3 40
Query design issue 2 18
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 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

21 Experts available now in Live!

Get 1:1 Help Now