Solved

Formatting data into date  / query

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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