Solved

Formatting data into date  / query

Posted on 2012-04-13
3
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

739 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